Merge pull request #18472 from sotux/master
[feed/packages.git] / net / softflowd / files / softflowd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007-2011 OpenWrt.org
3
4 USE_PROCD=1
5 START=50
6
7 append_bool() {
8 local section="$1"
9 local option="$2"
10 local value="$3"
11 local _val
12 config_get_bool _val "$section" "$option" '0'
13 [ "$_val" -gt 0 ] && append args "$3"
14 }
15
16 append_string() {
17 local section="$1"
18 local option="$2"
19 local value="$3"
20 local _val
21 config_get _val "$section" "$option"
22 [ -n "$_val" ] && append args "$3 $_val"
23 }
24
25 start_instance() {
26 local section="$1"
27
28 config_get_bool enabled "$section" 'enabled' '0'
29 [ "$enabled" -gt 0 ] || return 1
30
31 config_get pid_file "$section" 'pid_file'
32 config_get filter "$section" 'filter'
33
34 args=""
35 append_string "$section" 'interface' '-i'
36 append_string "$section" 'pcap_file' '-r'
37 append_string "$section" 'timeout' '-t'
38 append_string "$section" 'max_flows' '-m'
39 append_string "$section" 'host_port' '-n'
40 append_string "$section" 'pid_file' '-p'
41 append_string "$section" 'control_socket' '-c'
42 append_string "$section" 'export_version' '-v'
43 append_string "$section" 'hoplimit' '-L'
44 append_string "$section" 'tracking_level' '-T'
45 append_string "$section" 'sampling_rate' '-s'
46 append_bool "$section" track_ipv6 '-6'
47
48 procd_open_instance
49 procd_set_param command /usr/sbin/softflowd -d $args${pid_file:+ -p $pid_file} "$filter"
50 procd_set_param respawn
51 procd_close_instance
52 }
53
54 start_service() {
55 mkdir -p /var/empty
56 chmod 0755 /var/empty
57
58 config_load 'softflowd'
59 config_foreach start_instance 'softflowd'
60 }