4fbb87547aff7ec46cb117d7d153414bc2daeeda
[10.03/packages.git] / net / softflowd / files / softflowd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 OpenWrt.org
3 START=50
4
5 NAME=softflowd
6 BIN_F=/usr/sbin/$NAME
7 SSD=start-stop-daemon
8
9 append_bool() {
10         local section="$1"
11         local option="$2"
12         local value="$3"
13         local _val
14         config_get_bool _val "$section" "$option" '0'
15         [ "$_val" -gt 0 ] && append args "$3"
16 }
17
18 append_string() {
19         local section="$1"
20         local option="$2"
21         local value="$3"
22         local _val
23         config_get _val "$section" "$option"
24         [ -n "$_val" ] && append args "$3 $_val"
25 }
26
27 start_service() {
28         local section="$1"
29         args=""
30
31         append_string "$section" interface "-i"
32         append_string "$section" pcap_file "-r"
33         append_string "$section" timeout "-t"
34         append_string "$section" max_flows "-m"
35         append_string "$section" host_port "-n"
36         append_string "$section" pid_file "-p"
37         append_string "$section" control_socket "-c"
38         append_string "$section" export_version "-v"
39         append_string "$section" hoplimit "-L"
40         append_string "$section" tracking_level "-T"
41         append_bool "$section" track_ipv6 "-6"
42         config_get_bool "enabled" "$section" "enabled" '1'
43         [ "$enabled" -gt 0 ] && $BIN_F $args
44 }
45
46 stop_service() {
47         local section="$1"
48         config_get pidfile "$section" pid_file
49         config_get control_socket "$section" control_socket
50
51         [ -n "$pid_file" ] || pid_file="$pidfile"
52         # FIXME
53         $SSD -K -p $pid_file -q && rm -f $control_socket
54 }
55
56 start() {
57         mkdir -p /var/empty
58
59         config_load $NAME
60         config_foreach start_service $NAME
61 }
62
63 stop() {
64         config_load $NAME
65         config_foreach stop_service $NAME
66 }