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