luci-app-olsrd2: upgrade uci-defaults for ucitrack handling to use json
[feed/routing.git] / alfred / files / alfred.init
1 #!/bin/sh /etc/rc.common
2
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 START=99
9 USE_PROCD=1
10 alfred_args=""
11 vis_args=""
12 facters_dir="/etc/alfred"
13 enable=0
14 vis_enable=0
15
16 append_interface()
17 {
18 append "interfaces" "$1" ","
19 }
20
21 alfred_start() {
22 local args=""
23 local section="$1"
24 local disabled interface mode
25 local interfaces
26
27 # check if section is disabled
28 config_get_bool disabled "$section" disabled 0
29 [ $disabled = 0 ] || return 1
30
31 args="-f"
32
33 config_list_foreach "$section" "interface" append_interface
34 if [ -z "$interfaces" ]; then
35 config_get interface "$section" interface
36 append_interface "$interface"
37 fi
38 append args "-i $interfaces"
39
40 config_get mode "$section" mode
41 [ "$mode" = "master" ] && append args "-m"
42
43 config_get batmanif "$section" batmanif
44 append args "-b $batmanif"
45
46 append alfred_args "$args"
47 enable=1
48
49 config_get_bool start_vis "$section" start_vis 0
50 if [ "$start_vis" = 1 ] && [ -x /usr/sbin/batadv-vis ]; then
51 vis_enable=1
52 append vis_args "-i $batmanif -s"
53 fi
54
55 config_get_bool run_facters "$section" run_facters 0
56
57 return 0
58 }
59
60 start_service() {
61 config_load "alfred"
62 config_foreach alfred_start alfred
63
64 [ "$enable" = "0" ] && return 0
65
66 procd_open_instance "alfred"
67 procd_set_param command /usr/sbin/alfred
68 procd_append_param command ${alfred_args}
69 procd_close_instance
70
71 [ "$vis_enable" = "1" ] && {
72 procd_open_instance "batadv-vis"
73 procd_set_param command /usr/sbin/batadv-vis
74 procd_append_param command ${vis_args}
75 procd_close_instance
76 }
77
78 [ "$run_facters" = "1" ] && {
79 ( for file in $facters_dir/* ; do [ -x $file ] && $file ; done )
80 if ! ( grep -q "for file in $facters_dir/\* ; do " /etc/crontabs/root 2>/dev/null ) ; then
81 echo "*/5 * * * * ( for file in $facters_dir/* ; do [ -x \$file ] && \$file ; done )" >> /etc/crontabs/root
82 /etc/init.d/cron enable
83 /etc/init.d/cron restart
84 fi
85 }
86 }
87
88 service_triggers() {
89 procd_add_reload_trigger "alfred"
90 }
91
92 stop_service() {
93 [ -e /etc/crontabs/root ] && {
94 sed "\|for file in $facters_dir/\* ; do |d" -i /etc/crontabs/root
95 /etc/init.d/cron restart
96 }
97 }