Home-Assistant Ubuntu Startup Script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: home-assistant | |
# Required-Start: $remote_fs | |
# Required-Stop: $remote_fs | |
# Should-Start: $all | |
# Should-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: home-assistant daemon | |
# Description: home-assistant daemon | |
### END INIT INFO | |
set -e | |
. /lib/lsb/init-functions | |
PROGNAME=/home/gravyflex/.local/bin/hass | |
NAME=hass | |
CONFIG_DIR='/home/gravyflex/.homeassistant' | |
DESC="Home Assistant" | |
LOGFILE=/home/gravyflex/.homeassistant/home-assistant.log | |
PID=/var/run/hass.pid | |
USER="gravyflex" | |
# Check if DAEMON binary exist | |
[ -f $PROGDIR$PROGNAME ] || exit 0 | |
HASS_OPTS="-c $CONFIG_DIR --daemon" | |
case "$1" in | |
start) | |
log_daemon_msg "Starting $DESC" "$NAME" | |
if start-stop-daemon --start --oknodo --pidfile $PID --startas $PROGNAME --chuid $USER -- $HASS_OPTS 1>/dev/null | |
then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" "$NAME" | |
if start-stop-daemon --retry TERM/5/KILL/5 --oknodo --stop --quiet --pidfile $PID 1>/dev/null | |
then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
reload) | |
log_daemon_msg "Reloading $DESC configuration" "$NAME" | |
if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID --exec $PROGNAME -- $HASS_OPTS 1>/dev/null | |
then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
restart|force-reload) | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
start-stop-daemon --retry TERM/5/KILL/5 --oknodo --stop --quiet --pidfile $PID 1>/dev/null | |
if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $PROGNAME -- $HASS_OPTS 1>/dev/null | |
then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
fi | |
;; | |
syntax) | |
$PROGNAME $HASS_OPTS -t | |
;; | |
status) | |
status_of_proc -p $PID $PROGNAME $NAME | |
;; | |
*) | |
log_action_msg "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|syntax|status}" | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment