- #!/bin/sh
- ### BEGIN INIT INFO
- # Provides: librenms
- # Required-Start: $network $syslog
- # Required-Stop: $network $syslog
- # Default-Start: 2 3 4 5
- # Default-Stop: 1
- # Short-Description: Start LibreNMS service
- ### END INIT INFO
- PATH=/sbin:/bin:/usr/sbin:/usr/bin
- . /lib/lsb/init-functions
- DAEMON=/opt/librenms/librenms-service.py
- PIDFILE=/var/run/librenms.pid
- test -x $DAEMON || exit 5
- LOCKFILE=/var/lock/librenms
- lock_librenms() {
- if [ -x /usr/bin/lockfile-create ]; then
- lockfile-create $LOCKFILE
- lockfile-touch $LOCKFILE &
- LOCKTOUCHPID="$!"
- fi
- }
- unlock_librenms() {
- if [ -x /usr/bin/lockfile-create ] ; then
- kill $LOCKTOUCHPID
- lockfile-remove $LOCKFILE
- fi
- }
- RUNASUSER=root
- case $1 in
- start)
- log_daemon_msg "Starting LibreNMS service" "librenms"
- if [ -z "$UGID" ]; then
- log_failure_msg "user \"$RUNASUSER\" does not exist"
- exit 1
- fi
- lock_librenms
- start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE
- status=$?
- unlock_librenms
- log_end_msg $status
- ;;
- stop)
- log_daemon_msg "Stopping LibreNMS service" "librenms"
- start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
- log_end_msg $?
- rm -f $PIDFILE
- ;;
- restart|force-reload)
- $0 stop && sleep 2 && $0 start
- ;;
- try-restart)
- if $0 status >/dev/null; then
- $0 restart
- else
- exit 0
- fi
- ;;
- reload)
- exit 3
- ;;
- status)
- status_of_proc $DAEMON "LibreNMS service"
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
- exit 2
- ;;
- esac