Optimize return value checks for luci-reload
[project/luci.git] / libs / uci / root / sbin / luci-reload
1 #!/bin/sh
2 . /etc/functions.sh
3
4 apply_config() {
5         config_get init "$1" init
6         config_get exec "$1" exec
7         config_get test "$1" test
8         
9         [ -n "$init" ] && reload_init "$2" "$init" "$test"
10         [ -n "$exec" ] && reload_exec "$2" "$exec" "$test"
11 }
12
13 reload_exec() {
14         [ -x $2 ] && {
15                 echo "Reloading $1... "
16                 $2 >/dev/null 2>&1
17                 [ -n "$3" -a "$?" != "$3" ] && echo '!!! Failed to reload' $1 '!!!'
18         }
19 }
20
21 reload_init() {
22         [ -x /etc/init.d/$2 ] && /etc/init.d/$2 enabled && {
23                 echo "Reloading $1... "
24                 /etc/init.d/$2 reload >/dev/null 2>&1
25                 [ -n "$3" -a "$?" != "$3" ] && echo '!!! Failed to reload' $1 '!!!'
26         }
27 }
28
29 config_load ucitrack
30
31 for i in $*
32 do
33         config_foreach apply_config $i $i
34 done