utilities: Remove ovs-monitor.
[sliver-openvswitch.git] / debian / openvswitch-wdt.init
1 #!/bin/sh 
2 #
3 # Example init.d script with LSB support.
4 #
5 # Please read this init.d carefully and modify the sections to
6 # adjust it to the program you want to run.
7 #
8 # Copyright (c) 2007, 2009 Javier Fernandez-Sanguino <jfs@debian.org>
9 #
10 # This is free software; you may redistribute it and/or modify
11 # it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; either version 2,
13 # or (at your option) any later version.
14 #
15 # This is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License with
21 # the Debian operating system, in /usr/share/common-licenses/GPL;  if
22 # not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
24 #
25 ### BEGIN INIT INFO
26 # Provides:          openvswitch-wdt
27 # Required-Start:    $network $local_fs $remote_fs
28 # Required-Stop:     $remote_fs
29 # Should-Start:      $named $syslog openvswitch-switch
30 # Should-Stop:       
31 # Default-Start:     2 3 4 5
32 # Default-Stop:      0 1 6
33 # Short-Description: Open vSwitch switch watchdog
34 ### END INIT INFO
35
36 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
37
38 DAEMON=/usr/sbin/ovs-wdt
39 NAME=openvswitch-wdt
40 DESC="Open vSwitch watchdog"
41
42 PIDFILE=/var/run/openvswitch/$NAME.pid 
43
44 test -x $DAEMON || exit 0
45
46 . /lib/lsb/init-functions
47
48 # Default options, these can be overriden by the information
49 # at /etc/default/$NAME
50 DAEMON_OPTS=""          # Additional options given to the daemon 
51
52 DODTIME=10              # Time to wait for the daemon to die, in seconds
53                         # If this value is set too low you might not
54                         # let some daemons to die gracefully and
55                         # 'restart' will not work
56                         
57 # Include defaults if available
58 if [ -f /etc/default/$NAME ] ; then
59     . /etc/default/$NAME
60 fi
61
62 set -e
63
64 running_pid() {
65 # Check if a given process pid's cmdline matches a given name
66     pid=$1
67     name=$2
68     [ -z "$pid" ] && return 1 
69     [ ! -d /proc/$pid ] &&  return 1
70     return 0
71 }
72
73 running() {
74 # Check if the process is running looking at /proc
75 # (works for all users)
76
77     # No pidfile, probably no daemon present
78     [ ! -f "$PIDFILE" ] && return 1
79     pid=`cat $PIDFILE`
80     running_pid $pid $DAEMON || return 1
81     return 0
82 }
83
84 start_daemon() {
85 # Start the process using the wrapper
86     if test $WDT_TIMEOUT != 0; then
87         start-stop-daemon --start --quiet -m --background --pidfile $PIDFILE \
88             --exec $DAEMON -- --timeout=$WDT_TIMEOUT --interval=$WDT_INTERVAL $DAEMON_OPTS 
89     fi
90
91     # Wait up to 3 seconds for the daemon to start.
92     for i in 1 2 3; do
93         if running; then
94             break
95         fi
96         sleep 1
97     done
98
99     echo $OOPS_REBOOT_TIME > /proc/sys/kernel/panic
100     echo 1 > /proc/sys/kernel/panic_on_oops
101 }
102
103 stop_daemon() {
104     start-stop-daemon -o --stop --pidfile $PIDFILE
105     rm $PIDFILE
106 }
107
108 case "$1" in
109   start)
110         log_daemon_msg "Starting $DESC " "$NAME"
111         # Check if it's running first
112         if running ;  then
113             log_progress_msg "apparently already running"
114             log_end_msg 0
115             exit 0
116         fi
117         if start_daemon && running ;  then
118             # It's ok, the daemon started and is running
119             log_end_msg 0
120         else
121             # Either we could not start it or it is not running
122             # after we did
123             # NOTE: Some daemons might die some time after they start,
124             # this code does not try to detect this and might give
125             # a false positive (use 'status' for that)
126             log_end_msg 1
127         fi
128         ;;
129   stop)
130         log_daemon_msg "Stopping $DESC" "$NAME"
131         if running ; then
132             # Only stop the daemon if we see it running
133             stop_daemon
134             log_end_msg $?
135         else
136             # If it's not running don't do anything
137             log_progress_msg "apparently not running"
138             log_end_msg 0
139             exit 0
140         fi
141         ;;
142   restart|force-reload)
143         log_daemon_msg "Restarting $DESC" "$NAME"
144         if running ;  then
145             stop_daemon
146             # Wait some sensible amount, some daemons need this
147             [ -n "$DIETIME" ] && sleep $DIETIME
148         fi
149         start_daemon
150         running
151         log_end_msg $?
152         ;;
153   status)
154         log_daemon_msg "Checking status of $DESC" "$NAME"
155         if running ;  then
156             log_progress_msg "running"
157             log_end_msg 0
158         else
159             log_progress_msg "apparently not running"
160             log_end_msg 1
161             exit 1
162         fi
163         ;;
164   # Use this if the daemon cannot reload
165   reload)
166         log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
167         log_warning_msg "cannot re-read the config file (use restart)."
168         ;;
169   *)
170         N=/etc/init.d/$NAME
171         echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
172         exit 1
173         ;;
174 esac
175
176 exit 0