Last change
on this file since 1273 was
1252,
checked in by price, 16 years ago
|
std-init.sh to put the usual initscript boilerplate in one place
|
File size:
2.0 KB
|
Line | |
---|
1 | # Typical Debian initscript, but as a library rather than copy-paste. |
---|
2 | # |
---|
3 | # Usage: |
---|
4 | # NAME=short-name |
---|
5 | # DESC="Textual description" |
---|
6 | # SCRIPTNAME=/etc/init.d/$NAME # default if omitted |
---|
7 | # . /lib/init/std-init.sh |
---|
8 | # do_start() { ... } |
---|
9 | # do_stop() { ... } |
---|
10 | # do_reload() { ... } # optional |
---|
11 | # std_init "$1" |
---|
12 | |
---|
13 | . /lib/init/vars.sh |
---|
14 | . /lib/lsb/init-functions |
---|
15 | |
---|
16 | [ -r /etc/default/"$NAME" ] && . /etc/default/"$NAME" |
---|
17 | |
---|
18 | SCRIPTNAME="${SCRIPTNAME:-/etc/init.d/$NAME}" |
---|
19 | |
---|
20 | have_reload() |
---|
21 | { |
---|
22 | type do_reload >/dev/null 2>/dev/null |
---|
23 | } |
---|
24 | |
---|
25 | usage_exit() |
---|
26 | { |
---|
27 | if have_reload; then |
---|
28 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
---|
29 | else |
---|
30 | echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
---|
31 | fi |
---|
32 | exit 3 |
---|
33 | } |
---|
34 | |
---|
35 | std_init() |
---|
36 | { |
---|
37 | local cmd |
---|
38 | case "$1" in |
---|
39 | start|stop|restart) |
---|
40 | cmd="$1" ;; |
---|
41 | reload) |
---|
42 | if have_reload; then cmd=reload; else usage_exit; fi ;; |
---|
43 | force-reload) |
---|
44 | if have_reload; then cmd=reload; else cmd=restart; fi ;; |
---|
45 | *) |
---|
46 | usage_exit ;; |
---|
47 | esac |
---|
48 | |
---|
49 | case $cmd in |
---|
50 | start) |
---|
51 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
---|
52 | do_start |
---|
53 | case "$?" in |
---|
54 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
55 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
56 | esac |
---|
57 | ;; |
---|
58 | stop) |
---|
59 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
---|
60 | do_stop |
---|
61 | case "$?" in |
---|
62 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
63 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
64 | esac |
---|
65 | ;; |
---|
66 | reload) |
---|
67 | log_daemon_msg "Reloading $DESC" "$NAME" |
---|
68 | do_reload |
---|
69 | log_end_msg $? |
---|
70 | ;; |
---|
71 | restart) |
---|
72 | log_daemon_msg "Restarting $DESC" "$NAME" |
---|
73 | do_stop |
---|
74 | case "$?" in |
---|
75 | 0|1) |
---|
76 | do_start |
---|
77 | case "$?" in |
---|
78 | 0) log_end_msg 0 ;; |
---|
79 | 1) log_end_msg 1 ;; # Old process is still running |
---|
80 | *) log_end_msg 1 ;; # Failed to start |
---|
81 | esac |
---|
82 | ;; |
---|
83 | *) |
---|
84 | # Failed to stop |
---|
85 | log_end_msg 1 |
---|
86 | ;; |
---|
87 | esac |
---|
88 | ;; |
---|
89 | esac |
---|
90 | |
---|
91 | : |
---|
92 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.