add new rc.common for standardized init scripts, convert existing init scripts
[oweals/openwrt.git] / openwrt / package / base-files / default / etc / rc.common
1 #!/bin/sh
2 . /etc/functions.sh
3
4 start() {
5         return 0
6 }
7
8 stop() {
9         return 0
10 }
11
12 reload() {
13         return 1
14 }
15
16 restart() {
17         stop
18         start
19 }
20
21 boot() {
22         start
23 }
24
25 shutdown() {
26         return 0
27 }
28
29 disable() {
30         rm -f /etc/rc.d/${initscript##*/}
31 }
32
33 enable() {
34         disable
35         ln -s /etc/init.d/${initscript##*/} /etc/rc.d/${initscript##*/}
36 }
37
38 depends() {
39         return 0
40 }
41
42 help() {
43         cat <<EOF
44 Syntax: $0 [command]
45
46 Available commands:
47         start   Start the service
48         stop    Stop the service
49         restart Restart the service
50         reload  Reload configuration files (or restart if that fails)
51         enable  Enable the service (load at boot time)
52         disable Disable the service
53 $EXTRA_HELP
54 EOF
55 }
56
57 initscript="$1"
58 action="$2"
59
60 . "$initscript"
61
62 cmds=
63 for cmd in $EXTRA_COMMANDS; do
64         cmds="$cmd) $cmd;;"
65 done
66 eval "case \"\$action\" in
67         start) start;;
68         stop) stop;;
69         reload) reload || restart;;
70         restart) restart;;
71         enable) enable;;
72         disable) disable;;
73         boot) boot;;
74         shutdown) shutdown;;
75         $cmds
76         *) help;;
77 esac"