Code

New init.d scripts for all distribution
[nagixsc.git] / init.d / nagixsc_http2nagios
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          nagixsc_http2nagios
4 # Required-Start:    $local_fs $remote_fs
5 # Required-Stop:     $local_fs $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      S 0 1 6
8 # Short-Description: Nag(IX)SC HTTP Push Server
9 # Description:       Nag(IX)SC HTTP Push Server
10 ### END INIT INFO
12 # Author: Sven Velt <sv@teamix.net>
14 # PATH should only include /usr/* if it runs after the mountnfs.sh script
15 PATH=/usr/sbin:/usr/bin:/sbin:/bin
16 DESC="Nag(IX)SC http2nagios"
17 NAME=nagixsc_http2nagios
18 DAEMONPATH=/usr/local/nagixsc
19 DAEMON=$DAEMONPATH/$NAME.py
20 CFGFILE=$DAEMONPATH/etc/http2nagios.cfg
21 DAEMON_ARGS="-c $CFGFILE"
22 PIDFILE=/var/run/$NAME.pid
23 SCRIPTNAME=/etc/init.d/$NAME
25 # Look for daemon and config file
26 if [ ! -r $DAEMON ]
27 then
28         echo "Daemon not found, exiting..."
29         exit 1
30 fi
32 if [ ! -r $CFGFILE ]
33 then
34         echo "Config file not found, exiting..."
35         exit 1
36 fi
38 is_running()
39 {
40         [ -f "$PIDFILE" ] || return 1
41         ps ax | grep "`cat $PIDFILE`" | grep $NAME | grep -qv grep
42         return $?
43 }
45 do_start()
46 {
47         is_running && return 1
48         $DAEMON -d $DAEMON_ARGS || return 2
49 }
51 do_stop()
52 {
53         is_running || return 1
54         kill -TERM "`cat $PIDFILE`" 2>/dev/null
55         sleep 1
56         is_running || kill -KILL "`cat $PIDFILE`" 2>/dev/null
57         if is_running
58         then
59                 return 1
60         fi
61         rm -f $PIDFILE
62 }
66 case "$1" in
67   start)
68         echo -n "Starting $DESC ... "
69         do_start
70         case "$?" in
71                 0|1) echo $NAME ;;
72                 2) echo "$NAME did not start" ;;
73         esac
74         ;;
75   stop)
76         echo -n "Stopping $DESC ... "
77         do_stop
78         if [ $? -eq 0 ]
79         then
80                 echo "stopped"
81         else
82                 echo "could NOT stop process!"
83         fi
84         ;;
85   restart|force-reload)
86         echo -n "Restarting $DESC ... "
87         do_stop
88         sleep 1
89         do_start
90         echo "done"
91         ;;
92   *)
93         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
94         exit 3
95         ;;
96 esac