packages/ptunnel: use new service functions
[packages.git] / net / ptunnel / files / ptunnel.init
index 99252d5..9524909 100644 (file)
@@ -1,40 +1,32 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2007-2009 OpenWrt.org
+# Copyright (C) 2007-2011 OpenWrt.org
 
 START=70
-BIN=ptunnel
-PIDCOUNT=0
 
-start() {
-       include /lib/network
-       scan_interfaces
-
-       config_load ptunnel
-       config_foreach start_ptunnel ptunnel
-       iptables -I OUTPUT 1 -p icmp -j ACCEPT 2> /dev/null
-}
-
-start_ptunnel() {
+start_instance() {
        local section="$1"
 
        config_get interface "$section" interface
        config_get ifname "$interface" ifname
 
        [ -z "$ifname" ] && {
-               echo "Error: Interface '$interface' not found" 1>&2
+               echo "${initscript}: Error: Interface '$interface' not found" 1>&2
                return 1
        }
 
-       PIDCOUNT="$(( ${PIDCOUNT} + 1))"
-       ${BIN} -c "$ifname" -daemon /var/run/ptunnel."$PIDCOUNT".pid> /dev/null
+       SERVICE_PID_FILE="/var/run/ptunnel.$ifname.pid"
+       service_start /usr/sbin/ptunnel -c "$ifname" -daemon $SERVICE_PID_FILE
 }
 
-stop() {
-       local pidfile
+start() {
+       include /lib/network
+       scan_interfaces
 
-       for pidfile in `ls /var/run/${BIN}.*.pid`
-       do
-               start-stop-daemon -K -s KILL -p "${pidfile}" -n "${BIN}" >/dev/null
-               rm -f "${pidfile}"
-       done
+       config_load 'ptunnel'
+       config_foreach start_instance 'ptunnel'
+       iptables -I OUTPUT 1 -p icmp -j ACCEPT 2> /dev/null
+}
+
+stop() {
+       service_stop /usr/sbin/ptunnel
 }