Hi,
I was searching for a solution to this for a while as I didn’t like restarting my docker container every time I made a config change.
For Docker, it turns out that everything comes back up much quicker if we just restart HA inside the container rather than restarting the whole container.
We can use the Restart button in the Configuration->General page but I also wanted to be able to trigger that from the command line so that it can be quickly restarted after saving any changes to yamls etc (which I do in through the SSH terminal). I’ve also incorporated this into a script which quickly checks that the config is okay, and if it is then it restarts HA.
After some digging on the API pages I realised you can call a service with curl:
curl -X POST -H "x-ha-access: yourpass" -H "Content-Type: application/json" <IP_address>:8123/api/services/homeassistant/restart
Note the -H "x-ha-access: yourpass" may not be required depending on your authorisation configuration.
That’s what I used to do. But as I said in my post, I wanted to just restart HA without restarting the whole container. It turns out everything comes back up much quicker if we just restart HA inside the container without restarting the whole container.
I didn’t realise it was slow until I was watching some YouTube videos where people were restarting HA and it was coming back up really quickly. And they weren’t using Docker. So I thought there must be a better way to do it rather than bringing the whole container down. It was taking 4-5 min each time to get everything fully restored.
I figure each time the container is restarted it needs to find/renegoitiate all the connections to other devices/services (from looking at the logs Ring & Nest were taking the most time) but there must be some caching or something which allows the connections to be persistent if you don’t bring down the container.
I wonder if it depends on what is configured in HA?
From looking at the logs, when I bring down the container it seems to take a while connecting with my Nest thermostat and Ring doorbell (also Ikea stuff but to a lesser extent). But if I restart without bringing down the container then it doesn’t hang when connecting with them at all.
In a Debian Supervisor installation use just type ha at a root ssh session to open the HA CLI:
root@HAssistant:~# ha
The Home Assistant CLI is a small and simple command line utility that allows
you to control and configure different aspects of Home Assistant
Usage:
ha [command]
Available Commands:
addons Install, update, remove and configure Home Assistant add-ons
audio Audio device handling.
authentication Authentication for Home Assistant users.
banner Prints the CLI Home Assistant banner along with some useful information
cli Get information, update or configure the Home Assistant cli backend
core Provides control of the Home Assistant Core
dns Get information, update or configure the Home Assistant DNS server
docker Docker backend specific for info and OCI configuration
hardware Provides hardware information about your system
help Help about any command
host Control the host/system that Home Assistant is running on
info Provides a general Home Assistant information overview
jobs Get information and manage running jobs
multicast Get information, update or configure the Home Assistant Multicast
network Network specific for updating, info and configuration imports
observer Get information, update or configure the Home Assistant observer
os Operating System specific for updating, info and configuration imports
resolution Resolution center of Supervisor, show issues and suggest solutions
snapshots Create, restore and remove snapshot backups
supervisor Monitor, control and configure the Home Assistant Supervisor
Flags:
–api-token string Home Assistant Supervisor API token
–config string Optional config file (default is $HOME/.homeassistant.yaml)
–endpoint string Endpoint for Home Assistant Supervisor (default is ‘supervisor’)
-h, --help help for ha
–log-level string Log level (defaults to Warn)
–no-progress Disable the progress spinner
–raw-json Output raw JSON from the API
Use “ha [command] --help” for more information about a command.
Thank you David.
Every now and then, HA stops functioning. Well, the UI doesn’t do anything, HA is unavailable from chrome browser, Always, so far, in the middle of the night.
I’m running HA on a NAS in a virtual machine.
The console is available, so being able to do a core restart is very handy in that case.
And it worked perfectly.
Tried out the curl at the top of the page, and it didn’t work for me with 401, so just wanted to post the solution. I’m assuming the auth mechanism has just been updated since the post.