wok annotate ndoutils/stuff/etc/init.d/ndo2db @ rev 13911

syslinux: remove keyboard help
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jan 23 23:39:46 2013 +0100 (2013-01-23)
parents
children 0d8a1a3edc72
rev   line source
erjo@8703 1 #!/bin/sh
erjo@8703 2 #
erjo@8703 3 #
erjo@8703 4 # chkconfig: 345 99 01
erjo@8703 5 # description: Nagios to mysql
erjo@8703 6 #
erjo@8703 7 # Author : Gaétan Lucas
erjo@8703 8 # Realase : 07/02/08
erjo@8703 9 # Version : 0.1 b
erjo@8703 10 # File : ndo2db
erjo@8703 11 # Description: Starts and stops the Ndo2db daemon
erjo@8703 12 # used to provide network services status in a database.
erjo@8703 13 #
erjo@8703 14
erjo@8703 15 status_ndo ()
erjo@8703 16 {
erjo@8703 17 if ps -p $NdoPID > /dev/null 2>&1; then
erjo@8703 18 return 0
erjo@8703 19 else
erjo@8703 20 return 1
erjo@8703 21 fi
erjo@8703 22
erjo@8703 23 return 1
erjo@8703 24 }
erjo@8703 25
erjo@8703 26 printstatus_ndo()
erjo@8703 27 {
erjo@8703 28 if status_ndo $1 $2; then
erjo@8703 29 echo "ndo (pid $NdoPID) is running..."
erjo@8703 30 else
erjo@8703 31 echo "ndo is not running"
erjo@8703 32 fi
erjo@8703 33 }
erjo@8703 34
erjo@8703 35 killproc_ndo ()
erjo@8703 36 {
erjo@8703 37 echo "kill $2 $NdoPID"
erjo@8703 38 kill $2 $NdoPID
erjo@8703 39 }
erjo@8703 40
erjo@8703 41 pid_ndo ()
erjo@8703 42 {
erjo@8703 43 if test ! -f $NdoRunFile; then
erjo@8703 44 echo "No lock file found in $NdoRunFile"
erjo@8703 45 echo -n " checking runing process..."
erjo@8703 46 NdoPID=`ps -ef|grep ndo2db|cut -c0-5`
erjo@8703 47 if [ -z "$NdoPID" ]; then
erjo@8703 48 echo " No ndo2db process found"
erjo@8703 49 exit 1
erjo@8703 50 else
erjo@8703 51 echo " found process pid: $NdoPID"
erjo@8703 52 echo -n " reinit $NdoRunFile ..."
erjo@8703 53 touch $NdoRunFile
erjo@8703 54 chown $NdoUser:$NdoGroup $NdoRunFile
erjo@8703 55 echo "$NdoPID" > $NdoRunFile
erjo@8703 56 echo " done"
erjo@8703 57 fi
erjo@8703 58 fi
erjo@8703 59
erjo@8703 60 NdoPID=`head $NdoRunFile`
erjo@8703 61 }
erjo@8703 62
erjo@8703 63 # Source function library
erjo@8703 64 # Solaris doesn't have an rc.d directory, so do a test first
erjo@8703 65 if [ -f /etc/rc.d/init.d/functions ]; then
erjo@8703 66 . /etc/rc.d/init.d/functions
erjo@8703 67 elif [ -f /etc/init.d/functions ]; then
erjo@8703 68 . /etc/init.d/functions
erjo@8703 69 fi
erjo@8703 70
erjo@8703 71 prefix=/usr
erjo@8703 72 exec_prefix=${prefix}/bin
erjo@8703 73 NdoBin=${exec_prefix}/ndo2db
erjo@8703 74 NdoCfgFile=/etc/nagios/ndo2db.cfg
erjo@8703 75 NdoRunFile=/var/run/nagios/ndo2db.run
erjo@8703 76 NdoLockDir=/var/lock/subsys
erjo@8703 77 NdoLockFile=ndo2db.lock
erjo@8703 78 NdoUser=nagios
erjo@8703 79 NdoGroup=nagios
erjo@8703 80
erjo@8703 81 # Check that ndo exists.
erjo@8703 82 if [ ! -f $NdoBin ]; then
erjo@8703 83 echo "Executable file $NdoBin not found. Exiting."
erjo@8703 84 exit 1
erjo@8703 85 fi
erjo@8703 86
erjo@8703 87 # Check that ndo.cfg exists.
erjo@8703 88 if [ ! -f $NdoCfgFile ]; then
erjo@8703 89 echo "Configuration file $NdoCfgFile not found. Exiting."
erjo@8703 90 exit 1
erjo@8703 91 fi
erjo@8703 92
erjo@8703 93 # See how we were called.
erjo@8703 94 case "$1" in
erjo@8703 95
erjo@8703 96 start)
erjo@8703 97 echo -n "Starting ndo:"
erjo@8703 98 touch $NdoRunFile
erjo@8703 99 chown $NdoUser:$NdoGroup $NdoRunFile
erjo@8703 100 $NdoBin -c $NdoCfgFile
erjo@8703 101 if [ -d $NdoLockDir ]; then
erjo@8703 102 touch $NdoLockDir/$NdoLockFile;
erjo@8703 103 fi
erjo@8703 104 ps -ef|grep ndo2db|cut -c0-5 > $NdoRunFile
erjo@8703 105 if [ $? -eq 0 ]; then
erjo@8703 106 echo " done."
erjo@8703 107 exit 0
erjo@8703 108 else
erjo@8703 109 echo " failed."
erjo@8703 110 $0 stop
erjo@8703 111 exit 1
erjo@8703 112 fi
erjo@8703 113 ;;
erjo@8703 114
erjo@8703 115 stop)
erjo@8703 116 echo -n "Stopping ndo: "
erjo@8703 117
erjo@8703 118 pid_ndo
erjo@8703 119 killproc_ndo
erjo@8703 120
erjo@8703 121 # now we have to wait for ndo to exit and remove its
erjo@8703 122 # own NdoRunFile, otherwise a following "start" could
erjo@8703 123 # happen, and then the exiting ndo will remove the
erjo@8703 124 # new NdoRunFile, allowing multiple ndo daemons
erjo@8703 125 # to (sooner or later) run
erjo@8703 126 #echo -n 'Waiting for ndo to exit .'
erjo@8703 127 for i in 1 2 3 4 5 6 7 8 9 10 ; do
erjo@8703 128 if status_ndo > /dev/null; then
erjo@8703 129 echo -n '.'
erjo@8703 130 sleep 1
erjo@8703 131 else
erjo@8703 132 break
erjo@8703 133 fi
erjo@8703 134 done
erjo@8703 135 if status_ndo > /dev/null; then
erjo@8703 136 echo
erjo@8703 137 echo 'Warning - ndo did not exit in a timely manner'
erjo@8703 138 else
erjo@8703 139 echo 'done.'
erjo@8703 140 fi
erjo@8703 141
erjo@8703 142 rm -f $NdoRunFile $NdoLockDir/$NdoLockFile
erjo@8703 143 ;;
erjo@8703 144
erjo@8703 145 status)
erjo@8703 146 pid_ndo
erjo@8703 147 printstatus_ndo ndo
erjo@8703 148 ;;
erjo@8703 149
erjo@8703 150 restart)
erjo@8703 151 $0 stop
erjo@8703 152 $0 start
erjo@8703 153 ;;
erjo@8703 154
erjo@8703 155 *)
erjo@8703 156 echo "Usage: ndo {start|stop|restart|status}"
erjo@8703 157 exit 1
erjo@8703 158 ;;
erjo@8703 159
erjo@8703 160 esac
erjo@8703 161
erjo@8703 162 # End of this script
erjo@8703 163