From ef91005f6c9b6a84a425f6612bf3efa33409e269 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Thu, 23 Jul 2015 14:53:37 -0400 Subject: [PATCH] add LSB script --- poller-service.init | 88 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 poller-service.init diff --git a/poller-service.init b/poller-service.init new file mode 100755 index 000000000..ff5b4766c --- /dev/null +++ b/poller-service.init @@ -0,0 +1,88 @@ +### BEGIN INIT INFO +# Provides: poller-service +# Required-Start: networking +# Required-Stop: networking +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: The LibreNMS poller-service daemon +# Description: The LibreNMS poller-service daemon +# This polls devices monitored by LibreNMS +### END INIT INFO + +./lib/lsb/init-functions + +NAME=poller-service + +DAEMON=/opt/librenms/poller-service.py + +PIDFILE=/var/run/poller-service.pid + +test -x $DAEMON || exit 5 + +case $1 in + + start) + # Checked the PID file exists and check the actual status of process + if [ -e $PIDFILE ]; then + status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?" + # If the status is SUCCESS then don't need to start again. + if [ $status = "0" ]; then + exit # Exit + fi + fi + # Start the daemon. + log_daemon_msg "Starting the process" "$NAME" + # Start the daemon with the help of start-stop-daemon + # Log the message appropriately + if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON ; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + stop) + # Stop the daemon. + if [ -e $PIDFILE ]; then + status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?" + if [ "$status" = 0 ]; then + start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE + /bin/rm -rf $PIDFILE + fi + else + log_daemon_msg "$NAME process is not running" + log_end_msg 0 + fi + ;; + restart) + # Restart the daemon. + $0 stop && sleep 2 && $0 start + ;; + + status) + # Check the status of the process. + if [ -e $PIDFILE ]; then + status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $? + else + log_daemon_msg "$NAME Process is not running" + log_end_msg 0 + fi + ;; + + reload) + # Reload the process. Basically sending some signal to a daemon to reload + # it configurations. + if [ -e $PIDFILE ]; then + start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME + log_success_msg "$NAME process reloaded successfully" + else + log_failure_msg "$PIDFILE does not exists" + fi + ;; + + *) + # For invalid arguments, print the usage message. + echo "Usage: $0 {start|stop|restart|reload|status}" + exit 2 + ;; +esac