-
-
Save justyns/7dbd13269d44245f3329f85d80cab69c to your computer and use it in GitHub Desktop.
home-assistant rc script for Freebsd
This file contains hidden or 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 | |
# $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