From 07780292ee133f25f46f64e25e32463f34ba66c6 Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Thu, 17 Jun 2010 14:50:00 +0200 Subject: [PATCH] New init.d scripts for all distribution Signed-off-by: Sven Velt --- init.d/nagixsc_conf2http | 85 +++++++++++++++------------------ init.d/nagixsc_http2nagios | 97 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 46 deletions(-) create mode 100644 init.d/nagixsc_http2nagios diff --git a/init.d/nagixsc_conf2http b/init.d/nagixsc_conf2http index 0a05158..b7724f3 100755 --- a/init.d/nagixsc_conf2http +++ b/init.d/nagixsc_conf2http @@ -5,8 +5,8 @@ # 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 @@ -15,24 +15,25 @@ 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 +# Look for daemon and config file +if [ ! -r $DAEMON ] +then + echo "Daemon not found, exiting..." + exit 1 +fi -# Read configuration variable file if it is present -# [ -r /etc/default/$NAME ] && . /etc/default/$NAME - -# 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() { @@ -44,57 +45,49 @@ 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 diff --git a/init.d/nagixsc_http2nagios b/init.d/nagixsc_http2nagios new file mode 100644 index 0000000..c1d3393 --- /dev/null +++ b/init.d/nagixsc_http2nagios @@ -0,0 +1,97 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: nagixsc_http2nagios +# 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 Push Server +# Description: Nag(IX)SC HTTP Push Server +### END INIT INFO + +# Author: Sven Velt + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/usr/sbin:/usr/bin:/sbin:/bin +DESC="Nag(IX)SC http2nagios" +NAME=nagixsc_http2nagios +DAEMONPATH=/usr/local/nagixsc +DAEMON=$DAEMONPATH/$NAME.py +CFGFILE=$DAEMONPATH/etc/http2nagios.cfg +DAEMON_ARGS="-c $CFGFILE" +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Look for daemon and config file +if [ ! -r $DAEMON ] +then + echo "Daemon not found, exiting..." + exit 1 +fi + +if [ ! -r $CFGFILE ] +then + echo "Config file not found, exiting..." + exit 1 +fi + +is_running() +{ + [ -f "$PIDFILE" ] || return 1 + ps ax | grep "`cat $PIDFILE`" | grep $NAME | grep -qv grep + return $? +} + +do_start() +{ + is_running && return 1 + $DAEMON -d $DAEMON_ARGS || return 2 +} + +do_stop() +{ + 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 +} + + + +case "$1" in + start) + echo -n "Starting $DESC ... " + do_start + case "$?" in + 0|1) echo $NAME ;; + 2) echo "$NAME did not start" ;; + esac + ;; + stop) + echo -n "Stopping $DESC ... " + do_stop + if [ $? -eq 0 ] + then + echo "stopped" + else + echo "could NOT stop process!" + fi + ;; + restart|force-reload) + echo -n "Restarting $DESC ... " + do_stop + sleep 1 + do_start + echo "done" + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + -- 2.30.2