init-script.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: myservice
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Put a short description of the service here
  9. # Description: Put a long description of the service here
  10. ### END INIT INFO
  11. DAEMON_DIR="/opt/ffstatus/"
  12. DAEMON_NAME=ffstatus
  13. # Add any command line options for your daemon here
  14. DAEMON_OPTS=""
  15. # This next line determines what user the script runs as.
  16. # Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
  17. DAEMON_USER=root
  18. # The process ID of the script when it runs is stored here:
  19. PIDFILE=/var/run/$DAEMON_NAME.pid
  20. [ -r /etc/default/ffstatus ] && . /etc/default/ffstatus
  21. DAEMON=$DAEMON_DIR/ffstatus-daemon.py
  22. . /lib/lsb/init-functions
  23. do_start () {
  24. log_daemon_msg "Starting $DAEMON_NAME daemon"
  25. start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS
  26. log_end_msg $?
  27. }
  28. do_stop () {
  29. log_daemon_msg "Stopping $DAEMON_NAME daemon"
  30. start-stop-daemon --stop --pidfile $PIDFILE --retry 10
  31. log_end_msg $?
  32. }
  33. case "$1" in
  34. start|stop)
  35. do_${1}
  36. ;;
  37. restart|force-reload)
  38. do_stop
  39. do_start
  40. ;;
  41. status)
  42. status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
  43. ;;
  44. *)
  45. echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
  46. exit 1
  47. ;;
  48. esac
  49. exit 0