summaryrefslogtreecommitdiffstats
path: root/startup/default-init.in
blob: b0f02a225361c2d2868dec04e4bdf19afccc892c (plain)
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
#!/bin/sh
#
# Copyright (c) 2016 Nagios(R) Core(TM) Development Team
#
# chkconfig: - 80 30
# description: Starts and stops the Nagios Remote Plugin Executor \
#              so a remote nagios server can run plugins on this host
#
### BEGIN INIT INFO
# Provides:           nrpe
# Required-Start:     $local_fs $remote_fs $time
# Required-Stop:      $local_fs $remote_fs
# Should-Start:       $syslog $network
# Should-Stop:        $syslog $network
# Default-Start:      2 3 4 5
# Default-Stop:       0 1 6
# Short-Description:  Starts and stops the Nagios Remote Plugin Executor
# Description:        Starts and stops the Nagios Remote Plugin Executor
#                     so a remote nagios server can run plugins on this host
### END INIT INFO


NRPE_BIN=@sbindir@/nrpe
NRPE_CFG=@pkgsysconfdir@/nrpe.cfg
LOCK_DIR=@subsyslockdir@
LOCK_FILE=@subsyslockfile@
PID_FILE=@piddir@/nrpe.pid

test -x $NRPE_BIN || exit 5

RETVAL=0
_set_rc (){ return; }

# Default these commands/functions to RedHat/CentOS etc. values
MSG_CMD="echo -n"
START_CMD="daemon --pidfile $PID_FILE"
TERM_CMD="killproc -p $PID_FILE $NRPE_BIN -TERM"
HUP_CMD="killproc -p $PID_FILE $NRPE_BIN -HUP"
PRT_STAT="echo"
STAT_MSG="echo -n Checking for nrpe daemon... "
STAT_CMD="status nrpe"
EXIT_CMD="exit"


# Source the function library
if [ -f /etc/rc.status ]; then

	. /etc/rc.status

	_set_rc (){ return $RETVAL; }

	# Set these commands/functions to SuSE etc. values
	START_CMD="startproc -p $PID_FILE"
	TERM_CMD="killproc -p $PID_FILE -TERM $NRPE_BIN"
	HUP_CMD="killproc -p $PID_FILE -HUP $NRPE_BIN"
	PRT_STAT="rc_status -v -r"
	STAT_CMD="checkproc -p $PID_FILE $NRPE_BIN"
	EXIT_CMD="rc_exit"
	rc_reset

elif [ -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

elif [ -f /lib/lsb/init-functions ]; then

	. /lib/lsb/init-functions

	MSG_CMD="log_daemon_msg"
	START_CMD="start_daemon -p $PID_FILE"
	PRT_STAT="log_end_msg"
	STAT_MSG=
	STAT_CMD="status_of_proc -p $PID_FILE $NRPE_BIN nrpe"

elif [ -f /etc/rc.d/functions ]; then

	. /etc/rc.d/functions

fi


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

start)
	# Start daemons.
	$MSG_CMD "Starting nrpe "
	$START_CMD $NRPE_BIN -c $NRPE_CFG -d
	RETVAL=$?
	if test "$PRT_STAT" = log_end_msg; then
		$PRT_STAT $RETVAL
	else
		_set_rc; $PRT_STAT
	fi
	if [ $RETVAL = 0 ]; then
		[ -d $LOCK_DIR ] && touch $LOCK_FILE || true
	fi
	;;

stop)
	# Stop daemons.
	$MSG_CMD "Shutting down nrpe "
	$TERM_CMD
	RETVAL=$?
	if test "$PRT_STAT" = log_end_msg; then
		$PRT_STAT $RETVAL
	else
		_set_rc; $PRT_STAT
	fi
	if [ $RETVAL = 0 ]; then
		[ -d $LOCK_DIR ] && rm -f $LOCK_FILE
	fi
	;;

restart|force-reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;

reload)
	$MSG_CMD "Reloading nrpe "
	$HUP_CMD
	RETVAL=$?
	if test "$PRT_STAT" = log_end_msg; then
		$PRT_STAT $RETVAL
	else
		_set_rc; $PRT_STAT
	fi
	;;

try-restart|condrestart)
	$STAT_CMD || exit 0
	$0 stop
	$0 start
	RETVAL=$?
	;;

status)
	$STAT_MSG
	$STAT_CMD
	RETVAL=$?
	if test "$PRT_STAT" != log_end_msg; then
		_set_rc; $PRT_STAT
	fi
	;;

*)
	echo "Usage: nrpe {start|stop|restart|reload|try-restart|condrestart|status}"
	exit 1
esac

$EXIT_CMD $RETVAL