From a240aa95791893bf623dcb5279074b4cf16506ce Mon Sep 17 00:00:00 2001 From: Marcin Jurkowski Date: Wed, 2 Sep 2015 23:58:13 +0200 Subject: [PATCH] owfs: convert init scripts to procd style Convert init.d scripts to use procd and take advantage of respawn feature. Signed-off-by: Marcin Jurkowski --- utils/owfs/files/owfs.conf | 7 +- utils/owfs/files/owfs.init | 113 +++++++++++++++++---------------- utils/owfs/files/owftpd.conf | 7 +- utils/owfs/files/owftpd.init | 109 ++++++++++++++++--------------- utils/owfs/files/owhttpd.conf | 7 +- utils/owfs/files/owhttpd.init | 108 +++++++++++++++++-------------- utils/owfs/files/owserver.conf | 7 +- utils/owfs/files/owserver.init | 107 +++++++++++++++++-------------- 8 files changed, 249 insertions(+), 216 deletions(-) diff --git a/utils/owfs/files/owfs.conf b/utils/owfs/files/owfs.conf index 3bb30a5426..b4859897af 100644 --- a/utils/owfs/files/owfs.conf +++ b/utils/owfs/files/owfs.conf @@ -1,11 +1,10 @@ config owfs 'owfs' option enabled 0 - option uid 0 - option gid 0 + option user root option readonly 0 option mountpoint '/mnt/owfs' option fuse_allow_other 0 option fuse_open_opt '' option error_level 0 - option options '' - list devices '-s localhost:4304' + list devices '-s' + list devices 'localhost:4304' diff --git a/utils/owfs/files/owfs.init b/utils/owfs/files/owfs.init index e70820feed..83c8913a03 100644 --- a/utils/owfs/files/owfs.init +++ b/utils/owfs/files/owfs.init @@ -1,75 +1,82 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=99 +START=95 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owfs -# Workaround insufficient /dev/fuse permissions and the lack of /etc/fuse.conf -DEFAULT_SERVICE_UID=0 -DEFAULT_SERVICE_GID=0 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owfs-specific + append_arg "$cfg" mountpoint "--mountpoint" /mnt/owfs + append_bool "$cfg" fuse_allow_other "--allow_other" + append_arg "$cfg" fuse_open_opt "--fuse_open_opt" + + # don't respawn fuse + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owfs() { - local config="owfs" - local args="" - - config_load "$config" - - local mountpoint - config_get mountpoint "$config" mountpoint /mnt/owfs - append args "--mountpoint=${mountpoint}" - - local fuse_allow_other - config_get_bool fuse_allow_other "$config" fuse_allow_other 0 - [ "${fuse_allow_other}" -eq 1 ] && append args "--allow_other" - - local fuse_open_opt - config_get fuse_open_opt "$config" fuse_open_opt - [ -n "${fuse_open_opt}" ] && append args "--fuse_open_opt=\"${fuse_open_opt}\"" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owfs } -start() { - start_owfs -} - -stop() { - service_stop /usr/bin/owfs +start_service() { + config_load owfs + config_foreach start_instance owfs } diff --git a/utils/owfs/files/owftpd.conf b/utils/owfs/files/owftpd.conf index 88322c941e..100162e2ab 100644 --- a/utils/owfs/files/owftpd.conf +++ b/utils/owfs/files/owftpd.conf @@ -1,9 +1,8 @@ config owftpd 'owftpd' option enabled 0 - option uid 0 - option gid 0 + option user root option readonly 0 option port 21 option error_level 0 - option options '' - list devices '-s localhost:4304' + list devices '-s' + list devices 'localhost:4304' diff --git a/utils/owfs/files/owftpd.init b/utils/owfs/files/owftpd.init index 010b2b939c..a7e17c9387 100644 --- a/utils/owfs/files/owftpd.init +++ b/utils/owfs/files/owftpd.init @@ -1,72 +1,81 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=99 +START=95 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owftpd -# Needed for restricted TCP port 21 -DEFAULT_SERVICE_UID=0 -DEFAULT_SERVICE_GID=0 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owftpd-specific + append_arg "$cfg" port "--port" + append_arg "$cfg" max_connections "--max_connections" + + procd_set_param respawn + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owftpd() { - local config="owftpd" - local args="" - - config_load "$config" - - local port - config_get port "$config" port - [ -n "${port}" ] && append args "--port=${port}" - - local max_connections - config_get max_connections "$config" max_connections - [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owftpd } - -start() { - start_owftpd -} - -stop() { - service_stop /usr/bin/owftpd +start_service() { + config_load owftpd + config_foreach start_instance owftpd } diff --git a/utils/owfs/files/owhttpd.conf b/utils/owfs/files/owhttpd.conf index e49e4ceb3b..a314cd1eab 100644 --- a/utils/owfs/files/owhttpd.conf +++ b/utils/owfs/files/owhttpd.conf @@ -1,9 +1,8 @@ config owhttpd 'owhttpd' option enabled 0 - option uid 65534 - option gid 65534 + option user root option readonly 0 option port 3001 option error_level 0 - option options '' - list devices '-s localhost:4304' + list devices '-s' + list devices 'localhost:4304' diff --git a/utils/owfs/files/owhttpd.init b/utils/owfs/files/owhttpd.init index fdabdbc260..868c9b4198 100644 --- a/utils/owfs/files/owhttpd.init +++ b/utils/owfs/files/owhttpd.init @@ -1,71 +1,81 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=99 +START=95 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owhttpd -DEFAULT_SERVICE_UID=65534 -DEFAULT_SERVICE_GID=65534 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owhttpd-specific + append_arg "$cfg" port "--port" + append_arg "$cfg" max_connections "--max_connections" + + procd_set_param respawn + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owhttpd() { - local config="owhttpd" - local args="" - - config_load "$config" - - local port - config_get port "$config" port - [ -n "${port}" ] && append args "--port=${port}" - - local max_connections - config_get max_connections "$config" max_connections - [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owhttpd } - -start() { - start_owhttpd -} - -stop() { - service_stop /usr/bin/owhttpd +start_service() { + config_load owhttpd + config_foreach start_instance owhttpd } diff --git a/utils/owfs/files/owserver.conf b/utils/owfs/files/owserver.conf index e000894621..ceb8a61e65 100644 --- a/utils/owfs/files/owserver.conf +++ b/utils/owfs/files/owserver.conf @@ -1,9 +1,8 @@ config owserver 'owserver' option enabled 0 - option uid 65534 - option gid 65534 + option user root option readonly 0 option port 4304 option error_level 0 - option options '' - list devices '-d /dev/ttyUSB0' + list devices '-d' + list devices '/dev/ttyUSB0' diff --git a/utils/owfs/files/owserver.init b/utils/owfs/files/owserver.init index bbf870d04c..7f91aeec06 100644 --- a/utils/owfs/files/owserver.init +++ b/utils/owfs/files/owserver.init @@ -1,70 +1,81 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=98 +START=90 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owserver -DEFAULT_SERVICE_UID=65534 -DEFAULT_SERVICE_GID=65534 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owserver-specific + append_arg "$cfg" port "--port" + append_arg "$cfg" max_connections "--max_connections" + + procd_set_param respawn + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owserver() { - local config="owserver" - local args="" - - config_load "$config" - - local port - config_get port "$config" port - [ -n "${port}" ] && append args "--port=${port}" - - local max_connections - config_get max_connections "$config" max_connections - [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owserver } -start() { - start_owserver -} - -stop() { - service_stop /usr/bin/owserver +start_service() { + config_load owserver + config_foreach start_instance owserver }