#!/sbin/openrc-run # These two facilitate the bindir variable substitution below. prefix=@prefix@ exec_prefix=@exec_prefix@ # This is a custom variable, and has the following default value if a # specific config file is not defined by the user. : ${NPCD_CONFIG:="@pkgsysconfdir@/npcd.cfg"} : ${NAGIOS_CFG:="@NAGIOS_CFG@"} # The rest are OpenRC variables. extra_commands="checkconfig" extra_started_commands="reload" command="@bindir@/npcd" command_args="-f ${NPCD_CONFIG}" pidfile="@piddir@/npcd.pid" verify="@pkgsysconfdir@/verify_pnp_config" depend(){ use logger after nagios } reload(){ checkconfig || return $? ebegin "Reloading configuration" start-stop-daemon --signal KILL --pidfile "${pidfile}" eend $? } checkconfig(){ ebegin "Verifying config files" # Save the output in case verification fails and errors are printed. OUTPUT=$( ${verify} -m bulk+npcd -p "${NPCD_CONFIG}" -c "${NAGIOS_CFG}") # Save the exit code from the verification so that `echo` doesn't # clobber it. Then, if verification failed, show its # output. Otherwise, succeed quietly. local exit_code=$? [ $exit_code -ne 0 ] && echo "${OUTPUT}" >&2 eend $exit_code } start_pre() { # Without this, the "start" action will appear to succeed even if # the config file contains errors, and the daemon fails to start. # Another approach would be to wait for the PID file to appear, but # this is fast enough and feels cleaner. checkconfig || return $? } stop_pre() { # If this is a restart, check to make sure the user's config # isn't busted before we stop the running daemon. if [ "${RC_CMD}" = "restart" ] ; then checkconfig || return $? fi }