Has anyone implemented a script that can be run via cron that will restart HA after suddenly stopping?
My setup generally runs flawlessly however occasionally it just stops for what I call no apparent reason (or at least I haven’t been able to figure out why). As luck would have it for some reason it typically does this late at night. I’ll wake to find my automation’s not working. I generally can get 1 to 2 weeks maybe before this happens and HA fails. On occasion it will do it more often. I realize that the proper approach is to determine why it stops but unfortunately I haven’t been able to figure that out. Since it seems to always happen at a inopportune time I was hoping this would be an acceptable work around.
My setup is on a RPi2 and I would like to setup a cron job that checks to see if the home-assistant service is running and if not fire it back up. Ideally I would have this check every hour. I actually found this information but before I attempted to try this I wanted to see if anyone already has something in place they are using and if they could share that information. I would also be interested in anyone has any other thoughts.
#!/bin/bash
service=replace_me_with_a_valid_service
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo “$service is running!!!”
else
/etc/init.d/$service start
fi
I suspect the service would be “sudo systemctl start home-assistant.service”
Thanks!