remove some redundant code
[openwrt.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() {
7 return 0
8 }
9
10 stop() {
11 return 0
12 }
13
14 reload() {
15 return 1
16 }
17
18 restart() {
19 trap '' TERM
20 stop "$@"
21 start "$@"
22 }
23
24 boot() {
25 start "$@"
26 }
27
28 shutdown() {
29 return 0
30 }
31
32 disable() {
33 name="$(basename "${initscript}")"
34 rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
35 rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
36 }
37
38 enable() {
39 name="$(basename "${initscript}")"
40 disable
41 [ "$START" ] && ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
42 [ "$STOP" ] && ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
43 }
44
45 enabled() {
46 name="$(basename "${initscript}")"
47 [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
48 }
49
50 depends() {
51 return 0
52 }
53
54 help() {
55 cat <<EOF
56 Syntax: $initscript [command]
57
58 Available commands:
59 start Start the service
60 stop Stop the service
61 restart Restart the service
62 reload Reload configuration files (or restart if that fails)
63 enable Enable service autostart
64 disable Disable service autostart
65 $EXTRA_HELP
66 EOF
67 }
68
69 initscript="$1"
70 [ "$#" -ge 1 ] && shift
71 action="$1"
72 [ "$#" -ge 1 ] && shift
73
74 . "$initscript"
75
76 cmds=
77 for cmd in $EXTRA_COMMANDS; do
78 cmds="${cmds:+$cmds$N}$cmd) $cmd \"\$@\";;"
79 done
80 eval "case \"\$action\" in
81 start) start \"\$@\";;
82 stop) stop \"\$@\";;
83 reload) reload \"\$@\" || restart \"\$@\";;
84 restart) restart \"\$@\";;
85 boot) boot \"\$@\";;
86 shutdown) shutdown \"\$@\";;
87 enable) enable \"\$@\";;
88 enabled) enabled \"\$@\";;
89 disable) disable \"\$@\";;
90 $cmds
91 *) help;;
92 esac"
This page took 0.048264 seconds and 5 git commands to generate.