Code

Added COPYING (GPLv2) and copyright headers to all source files.
[nagixsc.git] / init.d / nagixsc_http2nagios
1 #! /bin/sh
2 #
3 # nagixsc_http2nagios - start and stop the Nag(ix)SC HTTP server
4 # http://oss.teamix.org/projects/nagixsc
5 #
6 # Copyright (C) 2010 Sven Velt <sv@teamix.net>
7 #
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the
10 # Free Software Foundation; only version 2 of the License is applicable.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20 #
21 ### BEGIN INIT INFO
22 # Provides:          nagixsc_http2nagios
23 # Required-Start:    $local_fs $remote_fs
24 # Required-Stop:     $local_fs $remote_fs
25 # Default-Start:     2 3 4 5
26 # Default-Stop:      S 0 1 6
27 # Short-Description: Nag(IX)SC HTTP Push Server
28 # Description:       Nag(IX)SC HTTP Push Server
29 ### END INIT INFO
31 # PATH should only include /usr/* if it runs after the mountnfs.sh script
32 PATH=/usr/sbin:/usr/bin:/sbin:/bin
33 DESC="Nag(IX)SC http2nagios"
34 NAME=nagixsc_http2nagios
35 DAEMONPATH=/usr/local/nagixsc
36 DAEMON=$DAEMONPATH/$NAME.py
37 CFGFILE=$DAEMONPATH/etc/http2nagios.cfg
38 DAEMON_ARGS="-c $CFGFILE"
39 PIDFILE=/var/run/$NAME.pid
40 SCRIPTNAME=/etc/init.d/$NAME
42 # Look for daemon and config file
43 if [ ! -r $DAEMON ]
44 then
45         echo "Daemon not found, exiting..."
46         exit 1
47 fi
49 if [ ! -r $CFGFILE ]
50 then
51         echo "Config file not found, exiting..."
52         exit 1
53 fi
55 is_running()
56 {
57         [ -f "$PIDFILE" ] || return 1
58         ps ax | grep "`cat $PIDFILE`" | grep $NAME | grep -qv grep
59         return $?
60 }
62 do_start()
63 {
64         is_running && return 1
65         $DAEMON -d $DAEMON_ARGS || return 2
66 }
68 do_stop()
69 {
70         is_running || return 1
71         kill -TERM "`cat $PIDFILE`" 2>/dev/null
72         sleep 1
73         is_running || kill -KILL "`cat $PIDFILE`" 2>/dev/null
74         if is_running
75         then
76                 return 1
77         fi
78         rm -f $PIDFILE
79 }
83 case "$1" in
84   start)
85         echo -n "Starting $DESC ... "
86         do_start
87         case "$?" in
88                 0|1) echo $NAME ;;
89                 2) echo "$NAME did not start" ;;
90         esac
91         ;;
92   stop)
93         echo -n "Stopping $DESC ... "
94         do_stop
95         if [ $? -eq 0 ]
96         then
97                 echo "stopped"
98         else
99                 echo "could NOT stop process!"
100         fi
101         ;;
102   restart|force-reload)
103         echo -n "Restarting $DESC ... "
104         do_stop
105         sleep 1
106         do_start
107         echo "done"
108         ;;
109   *)
110         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
111         exit 3
112         ;;
113 esac