From bc7471330823fdd53bba27368cf9f5b7fe3c22c9 Mon Sep 17 00:00:00 2001 From: Kristof Provost Date: Mon, 10 Feb 2025 22:48:45 +0100 Subject: [PATCH] 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. --- ansible/templates/homeassistant | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) 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 -- 2.51.0