A way to restart Home Assistant in Docker after it freezes

Hello there!
I have 2 Home Assistant installations set up in Docker in different locations (different HA versions and different hardware). In both of them I’ve noticed that after a long time without a restart, Home Assistant tends to freeze when trying to restart it from the UI. Home Assistant freezes and has to be restarted manually from Docker software (QNAP). After restarting manually the next restart works correctly, but only for a while, because after a few days it stops working again. How can I force a restart from the automations? I checked service Reload, but it works just like hitting a restart i UI - it freezes and nothing happens…

I have checked the logs after restart, and it doesnt show like there were any problems…

Rafal

Same issue as this thread? Home assistant Docker 2025-1 bug

Hello fleskefjes,

Yes, it seems very simmilar, with that difference that in my situation it takes a few days before I finally freezes when trying to restart it from UI.

As I read, the solution was to make a new installation and add one-by-one all the integrations?

Rafal

Use command line integration to restart host.
You need ON to be reboot with some delay
OFF will be nothing

I don’t think it will turn OFF so likely you need to manually do this or have automation that does this by default. Potentially this could be part of ON command, to call HA API to turn OFF switch.

Could you have weird db issue?
Do you have ability to monitor startup? I use portainer for this.

Thanks! Restarting docker itself seems to be what I’m looking for… I’ve made some tests and I think it really forces HA to restart without freezing…
I’ve also got an automation that detects the right moment to restart, so so far so good…
Now I do need to make to run a SSH script (on host) from automation… I’ve tried AlexxIT/SSHCommand integration , but somehow I cant execute ‘docker’ command despite login as an admin…

Edit 2:
I’m getting an error, which looks like the docker command can’t be found using command_line…?
/bin/sh: docker: not found

Edit 3:
One step closer… The ‘docker’ pachage is installed in:

/share/CACHEDEV1_DATA/.qpkg/container-station/bin

I’ve noticed that path to “docker” is not defined when trying to execute command from HA:

echo $PATH
/command:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

and when performing it from Putty:

echo $PATH
/share/CACHEDEV1_DATA/.qpkg/container-station/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin

To get it work I had to make SSH keys using:
https://wiki.qnap.com/wiki/SSH:_How_To_Set_Up_Authorized_Keys

I’ve copied the private key to folder:

/config/ssh/id_rsa

Locate “docker” command using:

which docker
/share/CACHEDEV1_DATA/.qpkg/container-station/bin/docker

And then the full command from Home-assistant is like this:

command_line:
  - switch:
      command_on: "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /config/ssh/id_rsa [email protected] -p SSHPORT '/share/CACHEDEV1_DATA/.qpkg/container-station/bin/docker restart homeassistant'"
      name: Home Assistant restart

Of course change the USER, XXX and SSHPORT…
Rafal