index 0a051584a793e3fb42875349c2b95308eb515a70..b36f0a2227cb97f955cb6503be2bde942af69a18 100755 (executable)
--- a/init.d/nagixsc_conf2http
+++ b/init.d/nagixsc_conf2http
#! /bin/sh
+#
+# nagixsc_http2nagios - start and stop the Nag(ix)SC HTTP server
+# http://oss.teamix.org/projects/nagixsc
+#
+# Copyright (C) 2010 Sven Velt <sv@teamix.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; only version 2 of the License is applicable.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
### BEGIN INIT INFO
# Provides: nagixsc_conf2http
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
-# Short-Description: Nag(IX)SC HTTP Pull
-# Description: Nag(IX)SC HTTP Pull
+# Short-Description: Nag(IX)SC HTTP Pull Server
+# Description: Nag(IX)SC HTTP Pull Server
### END INIT INFO
-# Author: Sven Velt <sv@teamix.net>
-
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="Nag(IX)SC Conf2HTTP"
NAME=nagixsc_conf2http
-DAEMONPATH=/etc/nagios/nagixsc
+DAEMONPATH=/usr/local/nagixsc
DAEMON=$DAEMONPATH/$NAME.py
-DAEMON_ARGS="-c $DAEMONPATH/etc/conf2http.cfg"
+CFGFILE=$DAEMONPATH/etc/conf2http.cfg
+DAEMON_ARGS="-c $CFGFILE"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
-# Exit if the package is not installed
-[ -x "$DAEMON" ] || exit 0
-
-# Read configuration variable file if it is present
-# [ -r /etc/default/$NAME ] && . /etc/default/$NAME
+# Look for daemon and config file
+if [ ! -r $DAEMON ]
+then
+ echo "Daemon not found, exiting..."
+ exit 1
+fi
-# Load the VERBOSE setting and other rcS variables
-[ -f /etc/default/rcS ] && . /etc/default/rcS
-
-# Define LSB log_* functions.
-# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
-. /lib/lsb/init-functions
+if [ ! -r $CFGFILE ]
+then
+ echo "Config file not found, exiting..."
+ exit 1
+fi
is_running()
{
do_start()
{
is_running && return 1
- start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
- start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $DAEMON -- $DAEMON_ARGS || return 2
+ $DAEMON -d $DAEMON_ARGS || return 2
}
do_stop()
{
- start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
- RETVAL="$?"
- [ "$RETVAL" = 2 ] && return 2
- start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
- [ "$?" = 2 ] && return 2
+ is_running || return 1
+ kill -TERM "`cat $PIDFILE`" 2>/dev/null
+ sleep 1
+ is_running || kill -KILL "`cat $PIDFILE`" 2>/dev/null
+ if is_running
+ then
+ return 1
+ fi
rm -f $PIDFILE
- return "$RETVAL"
}
case "$1" in
start)
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ echo -n "Starting $DESC ... "
do_start
case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ 0|1) echo $NAME ;;
+ 2) echo "$NAME did not start" ;;
esac
;;
stop)
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ echo -n "Stopping $DESC ... "
do_stop
- case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
+ if [ $? -eq 0 ]
+ then
+ echo "stopped"
+ else
+ echo "could NOT stop process!"
+ fi
;;
restart|force-reload)
- log_daemon_msg "Restarting $DESC" "$NAME"
+ echo -n "Restarting $DESC ... "
do_stop
- case "$?" in
- 0|1)
- do_start
- case "$?" in
- 0) log_end_msg 0 ;;
- 1) log_end_msg 1 ;; # Old process is still running
- *) log_end_msg 1 ;; # Failed to start
- esac
- ;;
- *)
- # Failed to stop
- log_end_msg 1
- ;;
- esac
+ sleep 1
+ do_start
+ echo "done"
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2