I have the following shell command, which I intend to call from an actionable notification:
ha_update: "ha core update", however, when I run it I get an exit code 127
Am I doing something wrong? It appears the shells should run from within the homeassistant environment, and in the configuration folder, which all seems fine to me, so I don’t see why it wouldn’t work, unless there’s a permissions issue?
One possible solution would be to ssh from the container to the host and run your command that way.
There might be a better way to trigger an update, perhaps by calling a service. Unfortunately, I haven’t found one yet.
Is that command intended to get update info or to execute an actual update? I use a different installation method, so I don’t know. If it’s to run an update, it seems like a terrible idea to execute an HA update from the same running HA instance. It should probably be shut down properly before running an update.
Both supervised and HAOS can update core from the ui, and does (I would assume) the same thing as ha core update. It essentially downloads the new docker container, then restarts the HA container. I am sure there will be more to it, but this is also what people do to update container, albeit manually.
Yep,I just want to be able to run the update service from an action in a notification on my phone, rather than click through to the UI.
I see the content about SSH into HA, I may try that, but it’s too much effort for a trivial gain in the process (as it is, the notification action items in the UI page whether you can click the update button).
I’m very surprised it doesn’t work, obviously don’t understand the documentation where it says
If you are using Home Assistant Operating
System, the commands are executed in the
homeassistant container context.
So if you test or debug your script, it might make
sense to do this in the context of this container
to get the same runtime environment.
I thought that would mean it’s running exactly where I want it to be, since I ssh in to homeassistant all the time and can run this command when I do. Apparently I am not connecting to the ‘homeassistant container’. I thought I was. (I am familiar with docker and containers but apparently not the terminology/setup of HAOS).
There could be more to it.
What would happen if the ha command itself was stopped during the update? That is what would most likely happen if it was started by Home Assistant.
It might be necessary to make sure the ha command runs even after the homeassistant container has been stopped. This can get quite complicated. I think you’d have to run something like this on the host:
nohup ha core update > /dev/null 2>&1 < /dev/null &
From looking at the source code, it seems like the ha command just calls an API.
That means it shouldn’t cause too much trouble if it crashes during the update.
It also means there’s an easier way to trigger an update. We just need to call one of the endpoints. The SUPERVISOR_TOKEN environment variable should be available inside the homeassistant container.
This seems like it should work:
curl -sSL -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/core/update