wok view ndoutils/stuff/etc/init.d/ndo2db @ rev 16681

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