add a check to see if an init script is enabled
[openwrt/staging/mkresin.git] / package / base-files / files / etc / rc.common
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 . $IPKG_INSTROOT/etc/functions.sh
5
6 START=50
7
8 start() {
9 return 0
10 }
11
12 stop() {
13 return 0
14 }
15
16 reload() {
17 return 1
18 }
19
20 restart() {
21 stop
22 start
23 }
24
25 boot() {
26 start
27 }
28
29 shutdown() {
30 return 0
31 }
32
33 disable() {
34 name="$(basename "${initscript}")"
35 rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
36 }
37
38 enable() {
39 name="$(basename "${initscript}")"
40 disable
41 ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
42 }
43
44 enabled() {
45 name="$(basename "${initscript}")"
46 [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
47 }
48
49 depends() {
50 return 0
51 }
52
53 help() {
54 cat <<EOF
55 Syntax: $initscript [command]
56
57 Available commands:
58 start Start the service
59 stop Stop the service
60 restart Restart the service
61 reload Reload configuration files (or restart if that fails)
62 enable Enable service autostart
63 disable Disable service autostart
64 $EXTRA_HELP
65 EOF
66 }
67
68 initscript="$1"
69 action="$2"
70
71 . "$initscript"
72
73 cmds=
74 for cmd in $EXTRA_COMMANDS; do
75 cmds="${cmds:+$cmds$N}$cmd) $cmd;;"
76 done
77 eval "case \"\$action\" in
78 start) start;;
79 stop) stop;;
80 reload) reload || restart;;
81 restart) restart;;
82 boot) boot;;
83 shutdown) shutdown;;
84 enable) enable;;
85 enabled) enabled;;
86 disable) disable;;
87 $cmds
88 *) help;;
89 esac"