wok-next diff ndoutils/stuff/etc/init.d/ndo2db @ rev 8703

add:: ndoutils
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Thu Feb 17 23:12:37 2011 +0100 (2011-02-17)
parents
children 0d8a1a3edc72
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ndoutils/stuff/etc/init.d/ndo2db	Thu Feb 17 23:12:37 2011 +0100
     1.3 @@ -0,0 +1,163 @@
     1.4 +#!/bin/sh
     1.5 +# 
     1.6 +#
     1.7 +# chkconfig: 345 99 01
     1.8 +# description: Nagios to mysql
     1.9 +#
    1.10 +# Author : Gaétan Lucas
    1.11 +# Realase : 07/02/08
    1.12 +# Version : 0.1 b
    1.13 +# File : ndo2db
    1.14 +# Description: Starts and stops the Ndo2db daemon
    1.15 +#              used to provide network services status in a database.
    1.16 +#
    1.17 +  
    1.18 +status_ndo ()
    1.19 +{
    1.20 +	if ps -p $NdoPID > /dev/null 2>&1; then
    1.21 +	        return 0
    1.22 +	else
    1.23 +		return 1
    1.24 +	fi
    1.25 +
    1.26 +	return 1
    1.27 +}
    1.28 +
    1.29 +printstatus_ndo()
    1.30 +{
    1.31 +	if status_ndo $1 $2; then
    1.32 +		echo "ndo (pid $NdoPID) is running..."
    1.33 +	else
    1.34 +		echo "ndo is not running"
    1.35 +	fi
    1.36 +}
    1.37 +
    1.38 +killproc_ndo ()
    1.39 +{
    1.40 +	echo "kill $2 $NdoPID"
    1.41 +	kill $2 $NdoPID
    1.42 +}
    1.43 +
    1.44 +pid_ndo ()
    1.45 +{
    1.46 +	if test ! -f $NdoRunFile; then
    1.47 +		echo "No lock file found in $NdoRunFile"
    1.48 +		echo -n "         checking runing process..."
    1.49 +		NdoPID=`ps -ef|grep ndo2db|cut -c0-5`
    1.50 +		if [ -z "$NdoPID" ]; then
    1.51 +			echo "     No ndo2db process found"
    1.52 +			exit 1
    1.53 +		else
    1.54 +			echo "     found process pid: $NdoPID"
    1.55 +			echo -n "         reinit $NdoRunFile ..."
    1.56 +			touch $NdoRunFile
    1.57 +			chown $NdoUser:$NdoGroup $NdoRunFile
    1.58 +			echo "$NdoPID" > $NdoRunFile
    1.59 +			echo "     done"
    1.60 +		fi
    1.61 +	fi
    1.62 +
    1.63 +	NdoPID=`head $NdoRunFile`
    1.64 +}
    1.65 +
    1.66 +# Source function library
    1.67 +# Solaris doesn't have an rc.d directory, so do a test first
    1.68 +if [ -f /etc/rc.d/init.d/functions ]; then
    1.69 +	. /etc/rc.d/init.d/functions
    1.70 +elif [ -f /etc/init.d/functions ]; then
    1.71 +	. /etc/init.d/functions
    1.72 +fi
    1.73 +
    1.74 +prefix=/usr
    1.75 +exec_prefix=${prefix}/bin
    1.76 +NdoBin=${exec_prefix}/ndo2db
    1.77 +NdoCfgFile=/etc/nagios/ndo2db.cfg
    1.78 +NdoRunFile=/var/run/nagios/ndo2db.run
    1.79 +NdoLockDir=/var/lock/subsys
    1.80 +NdoLockFile=ndo2db.lock
    1.81 +NdoUser=nagios
    1.82 +NdoGroup=nagios
    1.83 +          
    1.84 +# Check that ndo exists.
    1.85 +if [ ! -f $NdoBin ]; then
    1.86 +   echo "Executable file $NdoBin not found.  Exiting."
    1.87 +   exit 1
    1.88 +fi
    1.89 +
    1.90 +# Check that ndo.cfg exists.
    1.91 +if [ ! -f $NdoCfgFile ]; then
    1.92 +   echo "Configuration file $NdoCfgFile not found.  Exiting."
    1.93 +   exit 1
    1.94 +fi
    1.95 +          
    1.96 +# See how we were called.
    1.97 +case "$1" in
    1.98 +
    1.99 +	start)
   1.100 +		echo -n "Starting ndo:"
   1.101 +		touch $NdoRunFile
   1.102 +		chown $NdoUser:$NdoGroup $NdoRunFile
   1.103 +		$NdoBin -c $NdoCfgFile
   1.104 +		if [ -d $NdoLockDir ]; then
   1.105 +			touch $NdoLockDir/$NdoLockFile;
   1.106 +	       	fi
   1.107 +		ps -ef|grep ndo2db|cut -c0-5 > $NdoRunFile
   1.108 +		if [ $? -eq 0 ]; then
   1.109 +			echo " done."
   1.110 +			exit 0
   1.111 +		else
   1.112 +			echo " failed."
   1.113 +			$0 stop
   1.114 +			exit 1
   1.115 +		fi
   1.116 +		;;
   1.117 +
   1.118 +	stop)
   1.119 +		echo -n "Stopping ndo: "
   1.120 +
   1.121 +		pid_ndo
   1.122 +		killproc_ndo
   1.123 +
   1.124 +		# now we have to wait for ndo to exit and remove its
   1.125 +		# own NdoRunFile, otherwise a following "start" could
   1.126 +		# happen, and then the exiting ndo will remove the
   1.127 +		# new NdoRunFile, allowing multiple ndo daemons
   1.128 +		# to (sooner or later) run
   1.129 +		#echo -n 'Waiting for ndo to exit .'
   1.130 +		for i in 1 2 3 4 5 6 7 8 9 10 ; do
   1.131 +		    if status_ndo > /dev/null; then
   1.132 +			echo -n '.'
   1.133 +			sleep 1
   1.134 +		    else
   1.135 +			break
   1.136 +		    fi
   1.137 +		done
   1.138 +		if status_ndo > /dev/null; then
   1.139 +		    echo 
   1.140 +		    echo 'Warning - ndo did not exit in a timely manner'
   1.141 +		else
   1.142 +		    echo 'done.'
   1.143 + 		fi
   1.144 +
   1.145 +		rm -f $NdoRunFile $NdoLockDir/$NdoLockFile
   1.146 +		;;
   1.147 +
   1.148 +	status)
   1.149 +		pid_ndo
   1.150 +		printstatus_ndo ndo
   1.151 +		;;
   1.152 +
   1.153 +	restart)
   1.154 +		$0 stop
   1.155 +		$0 start
   1.156 +		;;
   1.157 +
   1.158 +	*)
   1.159 +		echo "Usage: ndo {start|stop|restart|status}"
   1.160 +		exit 1
   1.161 +		;;
   1.162 +
   1.163 +esac
   1.164 +  
   1.165 +# End of this script
   1.166 +