Skip to content

Instantly share code, notes, and snippets.

@justyns
Forked from damoun/hass
Created September 26, 2016 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justyns/7dbd13269d44245f3329f85d80cab69c to your computer and use it in GitHub Desktop.
Save justyns/7dbd13269d44245f3329f85d80cab69c to your computer and use it in GitHub Desktop.
home-assistant rc script for Freebsd
#!/bin/sh
# $FreeBSD$
#
# PROVIDE: hass
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# hass_enable (bool): Set to NO by default.
# Set it to YES to enable home-assistant.
# hass_pidfile (path): Set to /var/run/home-assistant/hass.pid by default.
# hass_user (user): Set to hass by default.
# hass_config_dir (path): Set to /usr/local/etc/home-assistant/ by default.
# hass_logfile (path): Set to /var/log/home-assistant.log by default.
. /etc/rc.subr
name=hass
rcvar=${name}_enable
start_cmd=${name}_start
stop_cmd=${name}_stop
load_rc_config $name
: ${hass_enable:=NO}
: ${hass_pidfile:=/var/run/home-assistant/hass.pid}
: ${hass_user:=hass}
: ${hass_config_dir:=/usr/local/etc/home-assistant/}
: ${hass_logfile:=/var/log/home-assistant.log}
command=hass
command_args="-v --config $hass_config_dir --pid-file $hass_pidfile --daemon >>& $hass_logfile"
hass_start()
{
if [ -f $hass_pidfile ] && kill -0 $(cat $hass_pidfile) >/dev/null 2>&1 ; then
echo 'Service already running'
return 1
fi
echo 'Starting service'
su -m $hass_user -c "$command $command_args"
echo 'Service started'
}
hass_stop()
{
if [ ! -f $hass_pidfile ] || ! kill -0 $(cat $hass_pidfile) >/dev/null 2>&1 ; then
echo 'Service not running'
return 1
fi
echo 'Stopping service'
kill $(cat $hass_pidfile)
while ps -p $(cat $hass_pidfile) >/dev/null 2>&1 ; do sleep 1;done
echo 'Service stopped'
}
run_rc_command "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment