0

If I run

sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
hass --script check_config

the script works as intended, it reads a file called /home/.homeassistant/configuration.yaml

but if I create a shell-script that I run from rc.local:

./restart.sh > /tmp/log_restart &

restart.sh:

sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
hass --script check_config

I get this error:

file does not exist: /root/.homeassistant/configuration.yaml

It seems like the root folder is changed, what can I do?

0

The problem here is that what you're doing at first is all about setting up interactive shells and then working within those. The source ... line doesn't execute until the sudo line completes, they aren't run in the same context in the script.

To do this, what you should probably do is put just the source and hass lines in a script, and in rc.local run su -c /path/to/restart.sh homeassistant

Since rc.local runs as root you shouldn't need the sudo part

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.