Jelajahi Sumber

Modernize OpenRC init script (#150)

* startup/openrc-conf.in: fix the path to the nrpe config file.

The default path (NRPE_CFG) to the config file should be determined
from the build variable @sysconfdir@. However, a typo or a relic from
days past used the name @pgksysconfdir@ instead. This led to the
resulting openrc-conf being unusable, and this commit fixes it by
dropping the "pkg".

* startup/openrc-init.in: modernize the OpenRC init script.

Rewrite the OpenRC init script via three major changes to bring it up
to parity with the one we currently use on modern Gentoo systems. All
of these changes should be portable to other distributions.

1. Change the shebang from the deprecated value of /sbin/runscript
   to /sbin/openrc-run.

2. Drop the depend() function. The way OpenRC handles dependencies
   is a little bit weird... for example, the "use" function will only
   start services that exist in the same runlevel as NRPE. Since
   localmount, netmount, and nfsmount are needed earlier in the
   boot process, they'll never exist in the same runlevel as NRPE,
   and so it's pointless to have a "use" dependency on them.

   The "use logger dns net" are a bit more arguable, but I don't think
   they're beneficial either. While NRPE can make use of them, it
   doesn't actually need them to run, and it is not desirable to start
   those services before NRPE is started: doing so prevents you from
   starting everything in parallel by introducing (ordered)
   dependencies. As a result, for general consumption, I think it's
   better to omit those dependencies so that NRPE can be started in
   parallel with everything else. This also avoids an annoying issue
   where if I've disabled my DNS client on purpose, restarting NRPE
   will bring it back up. The loopback interface and aforementioned
   boot-critical services are already guaranteed to be up, so nothing
   truly necessary will be missed.

   If users wish to add their own dependencies into the startup order,
   OpenRC can handle that, so this change doesn't preclude anyone from
   accomplishing the same thing in edge cases.

3. Drop the custom start/stop routines. OpenRC knows how to start/stop
   well-behaved daemons like NRPE, so the default start/stop routines
   work just fine and there's no need to duplicate them. This is
   accomplished largely by setting a few OpenRC variables
   (e.g. "command") at the top of the init script.
Michael Orlitzky 8 tahun lalu
induk
melakukan
caa4cbd1cc
2 mengubah file dengan 14 tambahan dan 46 penghapusan
  1. 3 3
      startup/openrc-conf.in
  2. 11 43
      startup/openrc-init.in

+ 3 - 3
startup/openrc-conf.in

@@ -1,7 +1,7 @@
 # /etc/conf.d/nrpe : config file for /etc/init.d/nrpe
 
-# Configuration file - default is @sysconfdir@/nrpe.cfg
-NRPE_CFG="@pgksysconfdir@/nrpe.cfg"
+# The configuration file to use.
+NRPE_CFG="@sysconfdir@/nrpe.cfg"
 
-# Any additional nrpe options (-n -4 -6)
+# Any additional options (e.g. -n -4 -6) to pass to the nrpe daemon.
 NRPE_OPTS=""

+ 11 - 43
startup/openrc-init.in

@@ -1,49 +1,17 @@
-#!/sbin/runscript
+#!/sbin/openrc-run
 #
-# Copyright (c) 2016 Nagios(R) Core(TM) Development Team
+# Copyright (c) 2017 Nagios(R) Core(TM) Development Team
 #
-# Start/stop the nrpe daemon.
-#
-# Goes in /etc/init.d - Config is in /etc/conf.d/nrpe
-
-opts="reload"
-# extra_started_commands="reload"		use this if OpenRC >= 0.9.4
-
-NRPE_BIN="@sbindir@/nrpe"
-NRPE_PID="@piddir@/nrpe.pid"
-
-depend() {
-	use logger dns net localmount netmount nfsmount
-}
 
-checkconfig() {
-	# Make sure the config file exists
-	if [ ! -f $NRPE_CFG ]; then
-		eerror "You need to setup $NRPE_CFG."
-		return 1
-	fi
-	return 0
-}
-
-start() {
-	checkconfig || return 1
-	ebegin "Starting nrpe"
-	# Make sure we have a sane current directory
-	cd /
-	start-stop-daemon --start --exec $NRPE_BIN --pidfile $PID_FILE \
-		--background -- -c $NRPE_CFG -f $NRPE_OPTS
-	eend $?
-}
-
-stop() {
-	ebegin "Stopping nrpe"
-	start-stop-daemon --stop --exec $NRPE_BIN --pidfile $PID_FILE
-	eend $?
-}
+command="@sbindir@/nrpe"
+command_args="--config=${NRPE_CFG} ${NRPE_OPTS}"
+command_args_background="--daemon"
+description="Nagios Remote Plugin Executor (NRPE) daemon"
+extra_started_commands="reload"
+pidfile="@piddir@/nrpe.pid"
 
 reload() {
-	ebegin "Reloading nrpe"
-	start-stop-daemon --stop --oknodo --exec $NRPE_BIN \
-		--pidfile $PID_FILE --signal HUP
-	eend $?
+    ebegin "Reloading ${SVCNAME}"
+    start-stop-daemon --signal HUP --pidfile "${pidfile}"
+    eend $?
 }