init-script.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. N INIT INFO
  2. # Provides: myservice
  3. # Required-Start: $remote_fs $syslog
  4. # Required-Stop: $remote_fs $syslog
  5. # Default-Start: 2 3 4 5
  6. # Default-Stop: 0 1 6
  7. # Short-Description: Put a short description of the service here
  8. # Description: Put a long description of the service here
  9. ### END INIT INFO
  10. DAEMON_DIR="/opt/ffstatus/"
  11. DAEMON_NAME="ffstatus"
  12. # Add any command line options for your daemon here
  13. DAEMON_OPTS=""
  14. # This next line determines what user the script runs as.
  15. # Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
  16. DAEMON_USER=root
  17. # The process ID of the script when it runs is stored here:
  18. PIDFILE=/var/run/$DAEMON_NAME.pid
  19. [ -r /etc/default/ffstatus ] && . /etc/default/ffstatus
  20. DAEMON=$DAEMON_DIR/myservice.py
  21. DAEMON_NAME=myservice
  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