From: Kristof Provost Date: Mon, 10 Feb 2025 21:48:45 +0000 (+0100) Subject: ansible: improve homeassistant startup script X-Git-Url: https://git.sigsegv.be/?a=commitdiff_plain;h=bc7471330823fdd53bba27368cf9f5b7fe3c22c9;p=pennestraat-domotica ansible: improve homeassistant startup script Ensure that 'status' and 'stop' actually work. This is still imperfect because we trust that the existence of the pidfile matches the existence of the process and that's only usually true. --- diff --git a/ansible/templates/homeassistant b/ansible/templates/homeassistant index 8906dab..4e3f85b 100644 --- a/ansible/templates/homeassistant +++ b/ansible/templates/homeassistant @@ -10,16 +10,41 @@ name="homeassistant" rcvar=${name}_enable pidfile=/var/run/${name}.pid -procname=/home/domotica/ha/bin/hass -start_precmd="ha_prestart" +ppidfile=/var/run/${name}-parent.pid +ha_command=/home/domotica/ha/bin/hass command=/usr/sbin/daemon -command_args=" -f -S -p ${pidfile} -u domotica ${procname} --ignore-os-check" +command_args=" -f -S -p ${pidfile} -P ${ppidfile} -u domotica ${ha_command} --ignore-os-check" + +start_precmd="ha_prestart" +status_cmd="ha_status" +stop_cmd="ha_stop" + ha_prestart() { chown -R domotica:domotica /home/domotica/ha } +ha_status() +{ + if [ -n "`cat $pidfile`" ]; then + echo "${name} is running as pid `cat $pidfile`." + else + echo ${name} is not running. + return 1 + fi +} + +ha_stop() +{ + echo "Stopping PID: $(cat ${ppidfile})" + /bin/kill -9 $(cat ${ppidfile}) + rm ${ppidfile} + echo "Stopping PID: $(cat ${pidfile})" + /bin/kill -15 $(cat ${pidfile}) + rm ${pidfile} +} + load_rc_config $name run_rc_command $1