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

uclibc-i486: add post_install
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 26 21:45:45 2012 +0100 (2012-02-26)
parents
children 0d8a1a3edc72
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 # See how we were called.
94 case "$1" in
96 start)
97 echo -n "Starting ndo:"
98 touch $NdoRunFile
99 chown $NdoUser:$NdoGroup $NdoRunFile
100 $NdoBin -c $NdoCfgFile
101 if [ -d $NdoLockDir ]; then
102 touch $NdoLockDir/$NdoLockFile;
103 fi
104 ps -ef|grep ndo2db|cut -c0-5 > $NdoRunFile
105 if [ $? -eq 0 ]; then
106 echo " done."
107 exit 0
108 else
109 echo " failed."
110 $0 stop
111 exit 1
112 fi
113 ;;
115 stop)
116 echo -n "Stopping ndo: "
118 pid_ndo
119 killproc_ndo
121 # now we have to wait for ndo to exit and remove its
122 # own NdoRunFile, otherwise a following "start" could
123 # happen, and then the exiting ndo will remove the
124 # new NdoRunFile, allowing multiple ndo daemons
125 # to (sooner or later) run
126 #echo -n 'Waiting for ndo to exit .'
127 for i in 1 2 3 4 5 6 7 8 9 10 ; do
128 if status_ndo > /dev/null; then
129 echo -n '.'
130 sleep 1
131 else
132 break
133 fi
134 done
135 if status_ndo > /dev/null; then
136 echo
137 echo 'Warning - ndo did not exit in a timely manner'
138 else
139 echo 'done.'
140 fi
142 rm -f $NdoRunFile $NdoLockDir/$NdoLockFile
143 ;;
145 status)
146 pid_ndo
147 printstatus_ndo ndo
148 ;;
150 restart)
151 $0 stop
152 $0 start
153 ;;
155 *)
156 echo "Usage: ndo {start|stop|restart|status}"
157 exit 1
158 ;;
160 esac
162 # End of this script