Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 56 lines (47 sloc) 1.83 KB
#!/bin/bash
# Daemon to auto-start up muni sign on Raspberry Pi load.
#
# If your user is 'pi', will write pidfile to ~pi/.munisign.pid.
set -e
USER=pi
USER_DIR="/home/$USER"
PIDFILE=$USER_DIR/.munisign.pid
ERROR_FILE=/tmp/null
# Replace with your data--or with a different script!
SCRIPT="$USER_DIR/sign/src/contrib/morning_room.rb"
declare -a SIGN_OPTIONS=(\
--update-interval 30 \
--route 30 --direction outbound --stop 'Townsend & 4th' \
--backup-route 45 --backup-direction outbound --backup-stop 'Townsend & 4th' \
--weather-url 'http://forecast.weather.gov/MapClick.php?lat=37.776905&lon=-122.395012&FcstType=digitalDWML' \
--weather-hour 20 )
# Uncomment these if you need muni sign emulation.
# SCRIPT="$USER_DIR/sign/src/client/client.rb"
# declare -a SIGN_OPTIONS=( --update-interval 30 --stopId 16995 )
# Darken the sign based on whether a specific file exists.
DARK_FILE=/tmp/muni-$USER-dark
SIGN_OPTIONS+=(--dark-file "$DARK_FILE")
# Require the file to be under an active update.
rm -f "$DARK_FILE"
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in
start)
echo "Starting muni sign"
start-stop-daemon --start --chdir "$USER_DIR" --quiet --chuid "$USER" --pidfile "$PIDFILE" --make-pidfile \
--exec "$SCRIPT" -- "${SIGN_OPTIONS[@]}" >/dev/null 2>$ERROR_FILE &
;;
stop)
echo "Stopping muni sign"
start-stop-daemon --stop --chdir "$USER_DIR" --quiet --chuid "$USER" --oknodo --pidfile "$PIDFILE"
;;
restart)
echo "Restarting muni sign"
start-stop-daemon --stop --chdir "$USER_DIR" --quiet --chuid "$USER" --oknodo --retry 30 --pidfile "$PIDFILE"
start-stop-daemon --start --chdir "$USER_DIR" --quiet --chuid "$USER" --pidfile "$PIDFILE" --make-pidfile \
--exec "$SCRIPT" -- "${SIGN_OPTIONS[@]}" >/dev/null 2>$ERROR_FILE &
;;
*)
echo "Usage: "$0" {start|stop|restart}"
exit 1
esac
exit 0