Merge pull request #388 from oneru/fwknop-qr
[project/luci.git] / modules / luci-base / root / sbin / luci-reload
1 #!/bin/sh
2 . /lib/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         echo "$2" > "/var/run/luci-reload-status"
10
11         [ -n "$init" ] && reload_init "$2" "$init" "$test"
12         [ -n "$exec" ] && reload_exec "$2" "$exec" "$test"
13 }
14
15 reload_exec() {
16         local service="$1"
17         local ok="$3"
18         set -- $2
19         local cmd="$1"; shift
20         
21         [ -x "$cmd" ] && {
22                 echo "Reloading $service... "
23                 ( $cmd "$@" ) 2>/dev/null 1>&2
24                 [ -n "$ok" -a "$?" != "$ok" ] && echo '!!! Failed to reload' $service '!!!'
25         }
26 }
27
28 reload_init() {
29         [ -x /etc/init.d/$2 ] && /etc/init.d/$2 enabled && {
30                 echo "Reloading $1... "
31                 /etc/init.d/$2 reload >/dev/null 2>&1
32                 [ -n "$3" -a "$?" != "$3" ] && echo '!!! Failed to reload' $1 '!!!'
33         }
34 }
35
36 lock "/var/run/luci-reload"
37
38 config_load ucitrack
39
40 for i in $*; do
41         config_foreach apply_config $i $i
42 done
43
44 rm -f "/var/run/luci-reload-status"
45 lock -u "/var/run/luci-reload"