File: rc.ido2db.in

package info (click to toggle)
icinga 1.13.4-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,068 kB
  • ctags: 18,809
  • sloc: ansic: 108,694; sql: 9,656; sh: 4,935; perl: 3,439; makefile: 1,242
file content (241 lines) | stat: -rw-r--r-- 5,345 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          ido2db
# Required-Start:    $remote_fs $syslog $named $network $time
# Required-Stop:     $remote_fs $syslog $named $network
# X-Start-Before:    icinga
# X-Stop-After:      icinga
# Should-Start:      mysql postgresql
# Should-Stop:       mysql postgresql
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Icinga IDO2DB Initscript
# Description: 	     Icinga Data Out Daemon
### END INIT INFO

# chkconfig: 345 98 01
#
# File : ido2db
#
# Author : Jorge Sanchez Aymar (jsanchez@lanchile.cl)
#
# Changelog :
#
# 1999-07-09 Karl DeBisschop <kdebisschop@infoplease.com>
#  - setup for autoconf
#  - add reload function
# 1999-08-06 Ethan Galstad <egalstad@nagios.org>
#  - Added configuration info for use with RedHat's chkconfig tool
#    per Fran Boon's suggestion
# 1999-08-13 Jim Popovitch <jimpop@rocketship.com>
#  - added variable for nagios/var directory
#  - cd into nagios/var directory before creating tmp files on startup
# 1999-08-16 Ethan Galstad <egalstad@nagios.org>
#  - Added test for rc.d directory as suggested by Karl DeBisschop
# 2000-07-23 Karl DeBisschop <kdebisschop@users.sourceforge.net>
#  - Clean out redhat macros and other dependencies
# 2003-01-11 Ethan Galstad <egalstad@nagios.org>
#  - Updated su syntax (Gary Miller)
# 2009-07-11 Hendrik Bäcker <andurin@process-zero.de>
#  - Rewrite ido2db init script, inspired by Sascha Runschke
#
#

servicename=@ido2db_name@
prefix=@prefix@
exec_prefix=${prefix}
Ido2dbBin=@bindir@/@ido2db_name@
Ido2dbCfgFile=@sysconfdir@/ido2db.cfg
Ido2dbRunFile=@IDO2DBLOCKFILE@
Ido2dbSockFile=@IDOSOCKFILE@
Ido2dbLockDir=/var/lock/subsys
Ido2dbLockFile=@ido2db_name@
Ido2dbUser=@icinga_user@
Ido2dbGroup=@icinga_grp@

#add ocilib lib path to link at runtime if enabled
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@ido2db_runtime@
export LD_LIBRARY_PATH


# load extra environment variables
if [ -f /etc/sysconfig/ido2db ]; then
	. /etc/sysconfig/ido2db
fi


# Source function library
# Solaris doesn't have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
	. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
	. /etc/init.d/functions
fi


# Check that ido2db exists.
if [ ! -f $Ido2dbBin ]; then
	echo "Executable file $Ido2dbBin not found.  Exiting."
	exit 1
fi

# Check that ido2db.cfg exists.
if [ ! -f $Ido2dbCfgFile ]; then
	echo "Configuration file $Ido2dbCfgFile not found.  Exiting."
	exit 1
fi

## helper functions ##

# checks status if ido2db daemon
# return 0 if running
# return 1 if dead but pidfile exists
# return 3 if daemon is not running
# return 4 if the state is unknown
status_ido2db ()
{
	if pid_ido2db && process_ido2db; then
		return 0
	elif ! pid_ido2db && ! process_ido2db; then
		return 3
	elif pid_ido2db; then
		return 1
	else
		return 4
	fi
}

# print human readable output of service status
printstatus_ido2db()
{
	status_ido2db $1 $2
	STATUS=$?
	if [ $STATUS -eq 0 ]; then
		echo "Ido2db (pid $Ido2dbPID) is running..."
	elif [ $STATUS -eq 1 ]; then
		echo "Ido2db is not running but subsystem locked"
	else
		echo "Ido2db is not running"
	fi
	exit $STATUS
}

# check if process is running
process_ido2db ()
{
	if ps -p $Ido2dbPID > /dev/null 2>&1; then
		return 0
	else
		return 1
	fi
}

# check pidfile for existence
pid_ido2db ()
{
	if test -f $Ido2dbRunFile && Ido2dbPID=`head -n 1 $Ido2dbRunFile`; then
		return 0
	else
		return 1
	fi
}

killproc_ido2db ()
{
	kill $Ido2dbPID

}

killproc9_ido2db ()
{
	kill -9 $Ido2dbPID

}

remove_run_files ()
{
	rm -f $Ido2dbRunFile $Ido2dbLockDir/$Ido2dbLockFile
}

## MAIN ##
# See how we were called.
case "$1" in

	start)
		#check if ido2db is already running
		status_ido2db
		STATUS=$?
		if test $STATUS -eq 0; then
			echo "Ido2db is already running. PID: $Ido2dbPID"
			exit 0
		elif test $STATUS -eq 1; then
			echo "Ido2db PID $Ido2dbPID not running. Removing lockfile."
			remove_run_files
		fi

		printf "Starting Ido2db:"
		# remove leftover sockfile, from a system crash
		rm -f $Ido2dbSockFile

		# precreate runfile and handover it to ido2db runuser and group
		touch $Ido2dbRunFile
		chown $Ido2dbUser:$Ido2dbGroup $Ido2dbRunFile

		# start ido2db daemon
		$Ido2dbBin -c $Ido2dbCfgFile
		bin_exit=$?
		if [ -d $Ido2dbLockDir ]; then touch $Ido2dbLockDir/$Ido2dbLockFile; fi
		echo " done."
		exit $bin_exit
		;;

	stop)
		if status_ido2db; then
			printf "Stopping Ido2db: "
			killproc_ido2db

			# now we have to wait for ido2db to exit and remove its
			# own Ido2dbRunFile, otherwise a following "start" could
			# happen, and then the exiting ido2db will remove the
			# new Ido2dbRunFile, allowing multiple ido2db daemons
			# to (sooner or later) run - John Sellens
			for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
				if status_ido2db; then
					printf '.'
					sleep 1
				else
					break
				fi
			done
			if status_ido2db; then
				echo ''
				echo "Warning - Ido2db did not exit in a timely manner. Sending kill -9"
                                killproc9_ido2db
			else
				remove_run_files
				echo "done."
			fi
		else
			echo "Ido2db is already stopped!"
			exit 0
		fi
		;;

	status)
		printstatus_ido2db
		;;

	restart)
		$0 stop
		$0 start
		;;

	*)
		echo "Usage: $servicename {start|stop|restart|status}"
		exit 1
		;;

	esac

	# End of this script