wprobe: add init script for exporter
authorFelix Fietkau <nbd@openwrt.org>
Sun, 29 Mar 2009 05:01:25 +0000 (05:01 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 29 Mar 2009 05:01:25 +0000 (05:01 +0000)
SVN-Revision: 15066

package/wprobe/Makefile
package/wprobe/files/wprobe.init [new file with mode: 0755]

index 89f0450f02ad26d0c9e859c23f662a315d37f219..7fccaa2baf7b08638ee56d52ddf7d25ab128fe58 100644 (file)
@@ -103,7 +103,8 @@ define Package/wprobe-info/install
 endef
 
 define Package/wprobe-export/install
-       $(INSTALL_DIR) $(1)/sbin
+       $(INSTALL_DIR) $(1)/sbin $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/wprobe.init $(1)/etc/init.d/
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/exporter/wprobe-export $(1)/sbin/
 endef
 
diff --git a/package/wprobe/files/wprobe.init b/package/wprobe/files/wprobe.init
new file mode 100755 (executable)
index 0000000..3c62a03
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh /etc/rc.common
+START=90
+
+wprobe_ssd() {
+       local cfg="$1"; shift
+       local cmd="$1"; shift
+       start-stop-daemon "$cmd" -p "/var/run/wprobe-$cfg.pid" -b -x /sbin/wprobe-export -m -- "$@"
+}
+
+stop_wprobe() {
+       local cfg="$1"
+       [ -f "/var/run/wprobe-$cfg.pid" ] && wprobe_ssd "$cfg" -K
+       rm -f "/var/run/wprobe-$cfg.pid"
+}
+
+start_wprobe() {
+       local cfg="$1"
+       config_get ifname "$cfg" interface
+       config_get host "$cfg" host
+       config_get port "$cfg" port
+       config_get proto "$cfg" proto
+       case "$proto" in
+               sctp) proto="-s";;
+               tcp) proto="-t";;
+               udp) proto="-u";;
+               *) proto="-t";;
+       esac
+       [ -z "$ifname" -o -z "$host" ] && {
+               echo "wprobe-export: missing host or interface name in config $cfg"
+               return
+       }
+       wprobe_ssd "$cfg" -S "$proto" -i "$ifname" -c "$host" -p "${port:-4739}"
+}
+
+stop() {
+       for f in /var/run/wprobe-*.pid; do
+               CFG="${f%%.pid}"
+               CFG="${CFG##/var/run/wprobe-}"
+               stop_wprobe "$CFG"
+       done
+}
+
+start() {
+       config_load wprobe
+       config_foreach start_wprobe wprobe
+}