From Colorant Gibbon, 5 Years ago, written in Plain Text.
Embed
  1. #!/bin/sh
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides:        librenms
  5. # Required-Start:  $network $syslog
  6. # Required-Stop:   $network $syslog
  7. # Default-Start:   2 3 4 5
  8. # Default-Stop:    1
  9. # Short-Description: Start LibreNMS service
  10. ### END INIT INFO
  11.  
  12. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  13.  
  14. . /lib/lsb/init-functions
  15.  
  16. DAEMON=/opt/librenms/librenms-service.py
  17. PIDFILE=/var/run/librenms.pid
  18.  
  19. test -x $DAEMON || exit 5
  20.  
  21. LOCKFILE=/var/lock/librenms
  22.  
  23. lock_librenms() {
  24.  if [ -x /usr/bin/lockfile-create ]; then
  25.   lockfile-create $LOCKFILE
  26.   lockfile-touch $LOCKFILE &
  27.   LOCKTOUCHPID="$!"
  28.  fi
  29. }
  30.  
  31. unlock_librenms() {
  32.  if [ -x /usr/bin/lockfile-create ] ; then
  33.   kill $LOCKTOUCHPID
  34.   lockfile-remove $LOCKFILE
  35.  fi
  36. }
  37.  
  38. RUNASUSER=root
  39.  
  40. case $1 in
  41.  start)
  42.   log_daemon_msg "Starting LibreNMS service" "librenms"
  43.   if [ -z "$UGID" ]; then
  44.    log_failure_msg "user \"$RUNASUSER\" does not exist"
  45.    exit 1
  46.   fi
  47.   lock_librenms
  48.     start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE
  49.   status=$?
  50.   unlock_librenms
  51.   log_end_msg $status
  52.     ;;
  53.  stop)
  54.   log_daemon_msg "Stopping LibreNMS service" "librenms"
  55.     start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
  56.   log_end_msg $?
  57.   rm -f $PIDFILE
  58.     ;;
  59.  restart|force-reload)
  60.   $0 stop && sleep 2 && $0 start
  61.     ;;
  62.  try-restart)
  63.   if $0 status >/dev/null; then
  64.    $0 restart
  65.   else
  66.    exit 0
  67.   fi
  68.   ;;
  69.  reload)
  70.   exit 3
  71.   ;;
  72.  status)
  73.   status_of_proc $DAEMON "LibreNMS service"
  74.   ;;
  75.  *)
  76.   echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
  77.   exit 2
  78.   ;;
  79. esac