1 | #! /bin/sh |
---|
2 | ### BEGIN INIT INFO |
---|
3 | # Provides: invirt-dns |
---|
4 | # Required-Start: $local_fs $remote_fs |
---|
5 | # Required-Stop: $local_fs $remote_fs |
---|
6 | # Default-Start: 2 3 4 5 |
---|
7 | # Default-Stop: 0 1 6 |
---|
8 | # Short-Description: Invirt DNS server |
---|
9 | # Description: |
---|
10 | ### END INIT INFO |
---|
11 | |
---|
12 | # Author: Invirt project <invirt@mit.edu> |
---|
13 | |
---|
14 | # Do NOT "set -e" |
---|
15 | |
---|
16 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
---|
17 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
---|
18 | DESC="the Invirt DNS server" |
---|
19 | NAME=invirt-dns |
---|
20 | DAEMON=/usr/sbin/invirt-dns |
---|
21 | DAEMON_ARGS="" |
---|
22 | PIDFILE=/var/run/$NAME.pid |
---|
23 | SCRIPTNAME=/etc/init.d/$NAME |
---|
24 | |
---|
25 | # Exit if the package is not installed |
---|
26 | [ -x "$DAEMON" ] || exit 0 |
---|
27 | |
---|
28 | # Read configuration variable file if it is present |
---|
29 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
---|
30 | |
---|
31 | # Load the VERBOSE setting and other rcS variables |
---|
32 | . /lib/init/vars.sh |
---|
33 | |
---|
34 | # Define LSB log_* functions. |
---|
35 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
---|
36 | . /lib/lsb/init-functions |
---|
37 | |
---|
38 | # |
---|
39 | # Function that starts the daemon/service |
---|
40 | # |
---|
41 | do_start() |
---|
42 | { |
---|
43 | # Return |
---|
44 | # 0 if daemon has been started |
---|
45 | # 1 if daemon was already running |
---|
46 | # 2 if daemon could not be started |
---|
47 | daemon --running -n $NAME && return 1 |
---|
48 | daemon -r -O daemon.info -E daemon.err -n $NAME -U $DAEMON $DAEMON_ARGS || return 2 |
---|
49 | } |
---|
50 | |
---|
51 | # |
---|
52 | # Function that stops the daemon/service |
---|
53 | # |
---|
54 | do_stop() |
---|
55 | { |
---|
56 | # Return |
---|
57 | # 0 if daemon has been stopped |
---|
58 | # 1 if daemon was already stopped |
---|
59 | # 2 if daemon could not be stopped |
---|
60 | # other if a failure occurred |
---|
61 | daemon --stop -n $NAME |
---|
62 | RETVAL="$?" |
---|
63 | [ "$RETVAL" = 2 ] && return 2 |
---|
64 | # Many daemons don't delete their pidfiles when they exit. |
---|
65 | rm -f $PIDFILE |
---|
66 | return "$RETVAL" |
---|
67 | } |
---|
68 | |
---|
69 | case "$1" in |
---|
70 | start) |
---|
71 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
---|
72 | do_start |
---|
73 | case "$?" in |
---|
74 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
75 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
76 | esac |
---|
77 | ;; |
---|
78 | stop) |
---|
79 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
---|
80 | do_stop |
---|
81 | case "$?" in |
---|
82 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
83 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
84 | esac |
---|
85 | ;; |
---|
86 | #reload|force-reload) |
---|
87 | # |
---|
88 | # If do_reload() is not implemented then leave this commented out |
---|
89 | # and leave 'force-reload' as an alias for 'restart'. |
---|
90 | # |
---|
91 | #log_daemon_msg "Reloading $DESC" "$NAME" |
---|
92 | #do_reload |
---|
93 | #log_end_msg $? |
---|
94 | #;; |
---|
95 | restart|force-reload) |
---|
96 | # |
---|
97 | # If the "reload" option is implemented then remove the |
---|
98 | # 'force-reload' alias |
---|
99 | # |
---|
100 | log_daemon_msg "Restarting $DESC" "$NAME" |
---|
101 | do_stop |
---|
102 | case "$?" in |
---|
103 | 0|1) |
---|
104 | do_start |
---|
105 | case "$?" in |
---|
106 | 0) log_end_msg 0 ;; |
---|
107 | 1) log_end_msg 1 ;; # Old process is still running |
---|
108 | *) log_end_msg 1 ;; # Failed to start |
---|
109 | esac |
---|
110 | ;; |
---|
111 | *) |
---|
112 | # Failed to stop |
---|
113 | log_end_msg 1 |
---|
114 | ;; |
---|
115 | esac |
---|
116 | ;; |
---|
117 | *) |
---|
118 | #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
---|
119 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
---|
120 | exit 3 |
---|
121 | ;; |
---|
122 | esac |
---|
123 | |
---|
124 | : |
---|