Skip to content

Instantly share code, notes, and snippets.

@dafvid
Created December 21, 2022 22:45
Show Gist options
  • Select an option

  • Save dafvid/cacbe8b4e677d124f565d0ba38fa4d22 to your computer and use it in GitHub Desktop.

Select an option

Save dafvid/cacbe8b4e677d124f565d0ba38fa4d22 to your computer and use it in GitHub Desktop.
Homeassistant FreeBSD rc-script
#!/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.
#set -xv
. /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/homeassistant/hass.pid}
: ${hass_user:=hass}
: ${hass_config_dir:=/usr/local/etc/home-assistant/}
: ${hass_logfile:=/var/log/home-assistant.log}
: ${hass_command:=hass}
command=$hass_command
command_args="-v --config $hass_config_dir --pid-file $hass_pidfile --daemon --log-file $hass_logfile"
pidfile=$hass_pidfile
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