Mercurial > hg > beaglert
comparison resources/initd-bela_shutdown_switch @ 392:5587d7fa0108 prerelease
Added a new init.d script for the shutdown button and updated the bela script to use the Makefile to stop.
| author | andrewm | 
|---|---|
| date | Tue, 14 Jun 2016 21:39:06 +0100 | 
| parents | |
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 391:db1714fe2814 | 392:5587d7fa0108 | 
|---|---|
| 1 #!/bin/sh | |
| 2 # Script to start the GPIO shutdown button checker | |
| 3 # Adapted from Stephen C Phillips: | |
| 4 # http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/ | |
| 5 | |
| 6 ### BEGIN INIT INFO | |
| 7 # Provides: bela_shutdown_swtich | |
| 8 # Required-Start: | |
| 9 # Required-Stop: | |
| 10 # Default-Start: 2 3 4 5 | |
| 11 # Default-Stop: 0 1 6 | |
| 12 # Short-Description: Monitor the shutdown button on the Bela cape | |
| 13 # Description: Monitor the shutdown button on the Bela cape | |
| 14 ### END INIT INFO | |
| 15 | |
| 16 # Change the next 3 lines to suit where you install your script and what you want to call it | |
| 17 DIR=/root | |
| 18 DAEMON=$DIR/shutdown_switch.sh | |
| 19 DAEMON_NAME=shutdown_switch | |
| 20 | |
| 21 # Add any command line options for your daemon here | |
| 22 DAEMON_OPTS="" | |
| 23 | |
| 24 # This next line determines what user the script runs as. | |
| 25 # Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python. | |
| 26 DAEMON_USER=root | |
| 27 | |
| 28 # The process ID of the script when it runs is stored here: | |
| 29 PIDFILE=/var/run/$DAEMON_NAME.pid | |
| 30 | |
| 31 . /lib/lsb/init-functions | |
| 32 | |
| 33 do_start () { | |
| 34 log_daemon_msg "Starting system $DAEMON_NAME daemon" | |
| 35 start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS | |
| 36 log_end_msg $? | |
| 37 } | |
| 38 do_stop () { | |
| 39 log_daemon_msg "Stopping system $DAEMON_NAME daemon" | |
| 40 start-stop-daemon --stop --pidfile $PIDFILE --retry 10 | |
| 41 log_end_msg $? | |
| 42 } | |
| 43 | |
| 44 case "$1" in | |
| 45 | |
| 46 start|stop) | |
| 47 do_${1} | |
| 48 ;; | |
| 49 | |
| 50 restart|reload|force-reload) | |
| 51 do_stop | |
| 52 do_start | |
| 53 ;; | |
| 54 | |
| 55 status) | |
| 56 status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $? | |
| 57 ;; | |
| 58 | |
| 59 *) | |
| 60 echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}" | |
| 61 exit 1 | |
| 62 ;; | |
| 63 | |
| 64 esac | |
| 65 exit 0 | 
