procd: add a small script that handles config reloads until configd is ready
[openwrt/staging/mkresin.git] / package / base-files / files / etc / rc.common
1 #!/bin/sh
2 # Copyright (C) 2006-2012 OpenWrt.org
3
4 . $IPKG_INSTROOT/lib/functions.sh
5 . $IPKG_INSTROOT/lib/functions/service.sh
6
7 initscript=$1
8 action=${2:-help}
9 shift 2
10
11 start() {
12 return 0
13 }
14
15 stop() {
16 return 0
17 }
18
19 reload() {
20 return 1
21 }
22
23 restart() {
24 trap '' TERM
25 stop "$@"
26 start "$@"
27 }
28
29 boot() {
30 start "$@"
31 }
32
33 shutdown() {
34 stop
35 }
36
37 disable() {
38 name="$(basename "${initscript}")"
39 rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
40 rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
41 }
42
43 enable() {
44 name="$(basename "${initscript}")"
45 disable
46 [ -n "$START" -o -n "$STOP" ] || {
47 echo "/etc/init.d/$name does not have a START or STOP value"
48 return 1
49 }
50 [ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
51 [ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
52 }
53
54 enabled() {
55 name="$(basename "${initscript}")"
56 [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
57 }
58
59 depends() {
60 return 0
61 }
62
63 help() {
64 cat <<EOF
65 Syntax: $initscript [command]
66
67 Available commands:
68 start Start the service
69 stop Stop the service
70 restart Restart the service
71 reload Reload configuration files (or restart if that fails)
72 enable Enable service autostart
73 disable Disable service autostart
74 $EXTRA_HELP
75 EOF
76 }
77
78 # for procd
79 start_service() {
80 return 0
81 }
82
83 service_triggers() {
84 return 0
85 }
86
87 stop_service() {
88 return 0
89 }
90
91 ${INIT_TRACE:+set -x}
92
93 . "$initscript"
94
95 [ -n "$USE_PROCD" ] && {
96 . $IPKG_INSTROOT/lib/functions/procd.sh
97 basescript=$(readlink "$initscript")
98 rc_procd() {
99 procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
100 "$@"
101 procd_close_service
102 }
103
104 start() {
105 rc_procd start_service "$@"
106 }
107
108 stop() {
109 procd_kill "$(basename ${basescript:-$initscript})" "$1"
110 }
111
112 reload() {
113 start
114 }
115 }
116
117 ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
118 list_contains ALL_COMMANDS "$action" || action=help
119 [ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
120 $action "$@"