procd: convert various packages to procd style init.d scripts
authorJohn Crispin <john@openwrt.org>
Tue, 17 Sep 2013 21:45:30 +0000 (21:45 +0000)
committerJohn Crispin <john@openwrt.org>
Tue, 17 Sep 2013 21:45:30 +0000 (21:45 +0000)
Signed-off-by: John Crispin <blogic@openwrt.org>
SVN-Revision: 38023

package/network/config/netifd/files/etc/init.d/network
package/network/services/dnsmasq/files/dnsmasq.init
package/network/services/dropbear/files/dropbear.init
package/network/services/ipset-dns/files/ipset-dns.init
package/network/services/relayd/files/relay.init
package/network/services/uhttpd/files/uhttpd.init
package/system/procd/files/log.init
package/system/rpcd/files/rpcd.init
package/utils/busybox/files/sysntpd

index 75586452f0583d0a1c0c4bbb19044358a7dd3c98..8031802e8de6398f6b02d303eb550335e870aa90 100755 (executable)
@@ -3,17 +3,30 @@
 START=20
 STOP=90
 
-SERVICE_DAEMONIZE=1
-SERVICE_WRITE_PID=1
+USE_PROCD=1
 
-start() {
-       stop
+start_service() {
        [ -e /proc/sys/kernel/core_pattern ] && {
                ulimit -c unlimited
                echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern
        }
-       service_start /sbin/netifd
+       procd_open_instance
+       procd_set_param command /sbin/netifd
+       procd_set_param respawn
+       procd_close_instance
+}
+
+reload_service() {
+       ubus call network reload
+       /sbin/wifi down
+       /sbin/wifi up
+}
+
+stop_service() {
+       /sbin/wifi down
+}
 
+service_running() {
        setup_switch() { return 0; }
 
        include /lib/network
@@ -25,24 +38,20 @@ start() {
        /sbin/wifi up
 }
 
+service_triggers()
+{
+       procd_add_reload_trigger "network"
+}
+
 restart() {
        ifdown -a
        sleep 1
-       start
+       trap '' TERM
+       stop "$@"
+       start "$@"
 }
 
 shutdown() {
        ifdown -a
        stop
 }
-
-stop() {
-       /sbin/wifi down
-       service_stop /sbin/netifd
-}
-
-reload() {
-       ubus call network reload
-       /sbin/wifi down
-       /sbin/wifi up
-}
index 630c07d1d8ef405867a8dfb30c28115623c64339..a0aee8e02b4efa3221c623ea659a2dfd1781111d 100644 (file)
@@ -3,7 +3,8 @@
 
 START=60
 
-SERVICE_USE_PID=1
+USE_PROCD=1
+PROG=/usr/sbin/dnsmasq
 
 DNS_SERVERS=""
 DOMAIN=""
@@ -479,7 +480,12 @@ dhcp_hostrecord_add() {
        xappend "--host-record=$record"
 }
 
-start() {
+service_triggers()
+{
+       procd_add_reload_trigger "dhcp"
+}
+
+start_service() {
        include /lib/network
        scan_interfaces
 
@@ -488,6 +494,10 @@ start() {
 
        config_load dhcp
 
+       procd_open_instance
+       procd_set_param command $PROG -C $CONFIGFILE -k
+       procd_close_instance
+
        # before we can call xappend
        mkdir -p $(dirname $CONFIGFILE)
 
@@ -528,23 +538,19 @@ start() {
        config_foreach dhcp_cname_add cname
        echo >> $CONFIGFILE
 
-       service_start /usr/sbin/dnsmasq -C $CONFIGFILE && {
-               rm -f /tmp/resolv.conf
-               [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && {
-                       echo "search $DOMAIN" >> /tmp/resolv.conf
-               }
-               DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
-               for DNS_SERVER in $DNS_SERVERS ; do
-                       echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
-               done
+       rm -f /tmp/resolv.conf
+       [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && {
+               echo "search $DOMAIN" >> /tmp/resolv.conf
        }
+       DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
+       for DNS_SERVER in $DNS_SERVERS ; do
+               echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
+       done
 }
 
-stop() {
-       service_stop /usr/sbin/dnsmasq && {
-               [ -f /tmp/resolv.conf ] && {
-                       rm -f /tmp/resolv.conf
-                       ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
-               }
+stop_service() {
+       [ -f /tmp/resolv.conf ] && {
+               rm -f /tmp/resolv.conf
+               ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
        }
 }
index 9390833d30a6ddc484f83cce617f0991f306abaf..728767f0309e39d15cf3f5c2476c094e168cae13 100755 (executable)
@@ -123,7 +123,7 @@ start_service()
 
 service_triggers()
 {
-       procd_add_config_trigger "dropbear" "/etc/init.d/dropbear" "restart"
+       procd_add_reload_trigger "dropbear"
 }
 
 killclients()
index 7b732791eae34ed4609a90ac5f0d7d4127dc3f99..0a76fcc4cd17f76c8738e5112adbe4130d8ffaf7 100755 (executable)
@@ -3,9 +3,7 @@
 
 START=61
 
-SERVICE_DAEMONIZE=1
-SERVICE_WRITE_PID=1
-
+USE_PROCD=1
 
 find_nameserver() {
        . /lib/functions/network.sh
@@ -38,28 +36,22 @@ start_instance() {
 
        config_get port "$cfg" port $((PORT++))
 
-       SERVICE_PID_FILE="/var/run/ipset-dns-$port.pid" \
-               service_start /usr/sbin/ipset-dns "$ipset" "$ipset6" "$port" "$dns"
+       procd_open_instance
+       procd_set_param command /usr/sbin/ipset-dns "$ipset" "$ipset6" "$port" "$dns"
+       procd_set_param env NO_DAEMONIZE=1
+       procd_set_param respawn
+       procd_close_instance
+}
+
+service_triggers()
+{
+       procd_add_reload_trigger "ipset-dns"
 }
 
-start() {
+start_service() {
        PORT=53001
        DEFNS="$(find_nameserver)"
 
-       # required by ipset-dns to not daemonize itself
-       export NO_DAEMONIZE=1
-
        config_load ipset-dns
        config_foreach start_instance ipset-dns
 }
-
-stop() {
-       local pid
-       for pid in /var/run/ipset-dns-*.pid; do
-               [ -f "$pid" ] || continue
-               SERVICE_PID_FILE="$pid" \
-                       service_stop /usr/sbin/ipset-dns
-               rm -f "$pid"
-       done
-}
-
index 43ba6e10f40f78d289f38b14c85324e640ab4407..edc419c0b9b4a062055f18b9267890236df5d88f 100644 (file)
@@ -2,9 +2,12 @@
 # Copyright (c) 2011-2012 OpenWrt.org
 START=80
 
+USE_PROCD=1
+PROG=/usr/sbin/relayd
+
 resolve_ifname() {
        grep -qs "^ *$1:" /proc/net/dev && {
-               append args "-I $1"
+               procd_append_param command -I "$1"
                append ifaces "$1"
        }
 }
@@ -37,6 +40,9 @@ start_relay() {
                fi
        }
 
+        procd_open_instance
+        procd_set_param command "$PROG"
+
        local net networks
        config_get networks "$cfg" network
        for net in $networks; do
@@ -53,44 +59,41 @@ start_relay() {
 
        local ipaddr
        config_get ipaddr "$cfg" ipaddr
-       [ -n "$ipaddr" ] && append args "-L $ipaddr"
+       [ -n "$ipaddr" ] && procd_append_param command -L "$ipaddr"
 
        local gateway
        config_get gateway "$cfg" gateway
-       [ -n "$gateway" ] && append args "-G $gateway"
+       [ -n "$gateway" ] && procd_append_param command -G "$gateway"
 
        local expiry # = 30
        config_get expiry "$cfg" expiry
-       [ -n "$expiry" ] && append args "-t $expiry"
+       [ -n "$expiry" ] && procd_append_param command "$expiry"
 
        local retry # = 5
        config_get retry "$cfg" retry
-       [ -n "$retry" ] && append args "-p $retry"
+       [ -n "$retry" ] && procd_append_param command -p "$retry"
 
        local table # = 16800
        config_get table "$cfg" table
-       [ -n "$table" ] && append args "-T $table"
+       [ -n "$table" ] && procd_append_param command -T "$table"
 
        local fwd_bcast # = 1
        config_get_bool fwd_bcast "$cfg" forward_bcast 1
-       [ $fwd_bcast -eq 1 ] && append args "-B"
+       [ $fwd_bcast -eq 1 ] && procd_append_param command "-B"
 
        local fwd_dhcp # = 1
        config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
-       [ $fwd_dhcp -eq 1 ] && append args "-D"
+       [ $fwd_dhcp -eq 1 ] && procd_append_param command"-D"
 
-       service_start /usr/sbin/relayd $args
+       procd_close_instance
 }
 
-stop() {
-       for pid in /var/run/relay-*.pid; do
-               SERVICE_PID_FILE="$pid"
-               service_stop /usr/sbin/relayd
-               rm -f "$SERVICE_PID_FILE"
-       done
+service_triggers()
+{
+       procd_add_reload_trigger "network"
 }
 
-start() {
+start_service() {
        include /lib/network
        config_load network
        config_foreach start_relay interface
index 26fb0422a28931af2a04ddf939254c9035bf5c24..51f7547ca88c1dcd4bf45d720f771db0e46602d6 100755 (executable)
@@ -3,8 +3,7 @@
 
 START=50
 
-SERVICE_DAEMONIZE=1
-SERVICE_WRITE_PID=1
+USE_PROCD=1
 
 UHTTPD_BIN="/usr/sbin/uhttpd"
 PX5G_BIN="/usr/sbin/px5g"
@@ -17,7 +16,7 @@ append_arg() {
        local val
 
        config_get val "$cfg" "$var"
-       [ -n "$val" -o -n "$def" ] && append UHTTPD_ARGS "$opt ${val:-$def}"
+       [ -n "$val" -o -n "$def" ] && procd_append_param command "$opt" "${val:-$def}"
 }
 
 append_bool() {
@@ -28,7 +27,7 @@ append_bool() {
        local val
 
        config_get_bool val "$cfg" "$var" "$def"
-       [ "$val" = 1 ] && append UHTTPD_ARGS "$opt"
+       [ "$val" = 1 ] && procd_append_param command "$opt"
 }
 
 generate_keys() {
@@ -53,7 +52,6 @@ generate_keys() {
 
 start_instance()
 {
-       UHTTPD_ARGS=""
        UHTTPD_CERT=""
        UHTTPD_KEY=""
 
@@ -61,6 +59,9 @@ start_instance()
        local realm="$(uci_get system.@system[0].hostname)"
        local listen http https interpreter indexes path
 
+       procd_open_instance
+       procd_set_param command "$UHTTPD_BIN" -f
+
        append_arg "$cfg" home "-h"
        append_arg "$cfg" realm "-r" "${realm:-OpenWrt}"
        append_arg "$cfg" config "-c"
@@ -84,17 +85,17 @@ start_instance()
 
        config_get http "$cfg" listen_http
        for listen in $http; do
-               append UHTTPD_ARGS "-p $listen"
+                procd_append_param command -p "$listen"
        done
 
        config_get interpreter "$cfg" interpreter
        for path in $interpreter; do
-               append UHTTPD_ARGS "-i $path"
+               procd_append_param command -i "$path"
        done
 
        config_get indexes "$cfg" index_page
        for path in $indexes; do
-               append UHTTPD_ARGS "-I $path"
+               procd_append_param command -I "$path"
        done
 
        config_get https "$cfg" listen_https
@@ -116,29 +117,20 @@ start_instance()
                }
        }
 
-       SERVICE_PID_FILE=/var/run/uhttpd_${cfg}.pid
-       service_start $UHTTPD_BIN -f $UHTTPD_ARGS
+       procd_close_instance
 
        # Check if daemon is running, if not then
        # re-execute in foreground to display error.
-       sleep 1 && service_check $UHTTPD_BIN || \
-               $UHTTPD_BIN -f $UHTTPD_ARGS
+#      sleep 1 && service_check $UHTTPD_BIN || \
+#              $UHTTPD_BIN -f $UHTTPD_ARGS
 }
 
-stop_instance()
+service_triggers()
 {
-       local cfg="$1"
-
-       SERVICE_PID_FILE=/var/run/uhttpd_${cfg}.pid
-       service_stop $UHTTPD_BIN
+       procd_add_reload_trigger "uhttpd"
 }
 
-start() {
+start_service() {
        config_load uhttpd
        config_foreach start_instance uhttpd
 }
-
-stop() {
-       config_load uhttpd
-       config_foreach stop_instance uhttpd
-}
index 4a878fed99dba868c2f888684f4cf96d94bcde13..14fbdf8c5493f969b62b96d28b3c8e1dd99b28bf 100644 (file)
@@ -8,7 +8,6 @@ STOP=89
 USE_PROCD=1
 NAME=logread
 PROG=/sbin/logread
-PIDCOUNT=1
 
 start_service_file()
 {
@@ -24,8 +23,6 @@ start_service_file()
        procd_set_param command "$PROG" -f -F "$log_file" -p "$pid_file"
         [ -n "${log_size}" ] && procd_append_param command -S "$log_size"
        procd_close_instance
-
-       PIDCOUNT="$(( ${PIDCOUNT} + 1))"
 }
 
 start_service_remote()
@@ -43,8 +40,6 @@ start_service_remote()
        procd_set_param command "$PROG" -f -r "$log_ip" "${log_port:-514}" -p "$pid_file"
         [ "${log_proto}" != "udp" ] || procd_append_param command -u
        procd_close_instance
-
-       PIDCOUNT="$(( ${PIDCOUNT} + 1))"
 }
 
 service_triggers()
index 2132f16fd33dd3475582d914e65d333f59a55e8a..98b633365b8147384c27e18dbaf9750805ca99d2 100755 (executable)
@@ -2,11 +2,14 @@
 
 START=12
 
-SERVICE_DAEMONIZE=1
-SERVICE_WRITE_PID=1
+USE_PROCD=1
+NAME=rpcd
+PROG=/sbin/rpcd
 
-start() {
-       service_start /sbin/rpcd
+start_service() {
+       procd_open_instance
+       procd_set_param command "$PROG"
+       procd_close_instance
 }
 
 stop() {
index c40ee76da3ca1b0529063b1cb4a2255dc7e86358..d7a9807a87d144abcf8d82c8eea071e293b24faa 100755 (executable)
@@ -27,5 +27,11 @@ start_service() {
                        procd_append_param command -p $peer
                done
        }
+       procd_set_param respawn
        procd_close_instance
 }
+
+service_triggers()
+{
+       procd_add_reload_trigger "system"
+}