packages/softflowd: use new service functions, use softflowctl to stop softflowd...
[openwrt/svn-archive/archive.git] / net / softflowd / files / softflowd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007-2011 OpenWrt.org
3
4 START=50
5
6 append_bool() {
7 local section="$1"
8 local option="$2"
9 local value="$3"
10 local _val
11 config_get_bool _val "$section" "$option" '0'
12 [ "$_val" -gt 0 ] && append args "$3"
13 }
14
15 append_string() {
16 local section="$1"
17 local option="$2"
18 local value="$3"
19 local _val
20 config_get _val "$section" "$option"
21 [ -n "$_val" ] && append args "$3 $_val"
22 }
23
24 start_instance() {
25 local section="$1"
26
27 config_get_bool enabled "$section" 'enabled' '0'
28 [ $enabled -gt 0 ] || return 1
29
30 config_get pid_file "$section" 'pid_file'
31
32 args=""
33 append_string "$section" 'interface' '-i'
34 append_string "$section" 'pcap_file' '-r'
35 append_string "$section" 'timeout' '-t'
36 append_string "$section" 'max_flows' '-m'
37 append_string "$section" 'host_port' '-n'
38 append_string "$section" 'pid_file' '-p'
39 append_string "$section" 'control_socket' '-c'
40 append_string "$section" 'export_version' '-v'
41 append_string "$section" 'hoplimit' '-L'
42 append_string "$section" 'tracking_level' '-T'
43 append_bool "$section" track_ipv6 '-6'
44
45 SERVICE_PID_FILE="$pid_file" \
46 service_start /usr/sbin/softflowd $args${pid_file:+ -p $pid_file}
47 }
48
49 stop_instance() {
50 local section="$1"
51
52 config_get_bool enabled "$section" 'enabled' '0'
53 [ $enabled -gt 0 ] || return 1
54
55 config_get control_socket "$section" 'control_socket'
56
57 [ -n "control_socket" -a -S $control_socket ] && {
58 /usr/sbin/softflowctl -c $control_socket exit
59 }
60 }
61
62 start() {
63 mkdir -m 0755 -p /var/empty
64
65 config_load 'softflowd'
66 config_foreach start_instance 'softflowd'
67 }
68
69 stop() {
70 config_load 'softflowd'
71 config_foreach stop_instance 'softflowd'
72 service_stop /usr/sbin/softflowd
73 }