cf0b162181f16877ddf2547f2ee15792f4fb6bef
[openwrt.git] / package / wprobe / files / wprobe.init
1 #!/bin/sh /etc/rc.common
2 START=90
3 EXPORTER=/usr/sbin/wprobe-ipfix
4
5 wprobe_ssd() {
6         local cfg="$1"; shift
7         local cmd="$1"; shift
8         start-stop-daemon "$cmd" -p "/var/run/wprobe-$cfg.pid" -b -x "$EXPORTER" -m -- "$@"
9 }
10
11 stop_wprobe() {
12         local cfg="$1"
13         [ -f "/var/run/wprobe-$cfg.pid" ] && wprobe_ssd "$cfg" -K
14         rm -f "/var/run/wprobe-$cfg.pid"
15 }
16
17 config_wprobe() {
18         config_get ifname "$cfg" ifname
19         config_get interval "$cfg" interval
20         [ -n "$interval" ] || interval=100
21         wprobe-info "$ifname" -c -i "$interval"
22 }
23
24 start_ipfix() {
25         local cfg="$1"
26         config_get ifname "$cfg" interface
27         config_get host "$cfg" host
28         config_get port "$cfg" port
29         config_get proto "$cfg" proto
30         case "$proto" in
31                 sctp) proto="-s";;
32                 tcp) proto="-t";;
33                 udp) proto="-u";;
34                 *) proto="-t";;
35         esac
36         [ -z "$ifname" -o -z "$host" ] && {
37                 echo "wprobe-export: missing host or interface name in config $cfg"
38                 return
39         }
40         config_wprobe "$cfg"
41         wprobe_ssd "$cfg" -S "$proto" -i "$ifname" -c "$host" -p "${port:-4739}"
42 }
43
44 start_export() {
45         config_get export_type "$cfg" type
46         case "$export_type" in 
47                 ipfix) start_ipfix "$cfg";;
48         esac
49 }
50
51 stop() {
52         for f in /var/run/wprobe-*.pid; do
53                 CFG="${f%%.pid}"
54                 CFG="${CFG##/var/run/wprobe-}"
55                 stop_wprobe "$CFG"
56         done
57 }
58
59 start() {
60         config_load wprobe
61         config_foreach config_wprobe interface
62         [ -x "$EXPORTER" ] && config_foreach start_export export
63 }