How to start the home assistant core automatically

How to start the home assistant core Ubuntu automatically

1 Like

no way

root@xiaopan:~# sudo journalctl -f -u home-assistant@homeassistant-- Logs begin at Wed 2022-05-04 14:57:06 CST. --
5月 16 22:13:39 xiaopan systemd[1]: Started Home Assistant.
5月 16 22:13:39 xiaopan systemd[30503]: [email protected]: Failed to execute command: Permission denied
5月 16 22:13:39 xiaopan systemd[30503]: [email protected]: Failed at step EXEC spawning /srv/homeassistant: Permission denied
5月 16 22:13:39 xiaopan systemd[1]: [email protected]: Main process exited, code=exited, status=203/EXEC
5月 16 22:13:39 xiaopan systemd[1]: [email protected]: Failed with result 'exit-code'.
5月 16 22:15:57 xiaopan systemd[1]: Started Home Assistant.
5月 16 22:15:57 xiaopan systemd[30615]: [email protected]: Failed to execute command: Permission denied
5月 16 22:15:57 xiaopan systemd[30615]: [email protected]: Failed at step EXEC spawning /srv/homeassistant: Permission denied
5月 16 22:15:57 xiaopan systemd[1]: [email protected]: Main process exited, code=exited, status=203/EXEC
5月 16 22:15:57 xiaopan systemd[1]: [email protected]: Failed with result 'exit-code'.

Instead of posting no way, why not post your service file, location and permissions? That is exactly how I start HA Core on my Linux box.

I didn’t get it.

Is the user you start home assistant as in your virtual environment named “homeassistant” with no password?

Yes, that’s right

Assuming the install is in /srv/homeassistant and assuming “homeassistant” is the owner of this directory and assuming you created the service as stated above, it should work.

Mine is named: [email protected]

It’s contents are:

[Unit]
Description=Home Assistant
After=network-online.target

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"
RestartForceExitStatus=100
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

To me it looks like some permission problem in that directory.
Is there any clue if you execute:

sudo systemctl status home-assistant@homeassistant

1 Like

This result

pan@xiaopan:~$ sudo systemctl status home-assistant@homeassistant
● [email protected] - Home Assistant
     Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: en>
     Active: failed (Result: exit-code) since Mon 2022-05-16 23:47:10 CST; 2h 33min ago
    Process: 1603 ExecStart=/srv/homeassistant && source bin/activate && hass (code=exited, status=203/EX>
   Main PID: 1603 (code=exited, status=203/EXEC)

5月 16 23:47:10 xiaopan systemd[1]: Started Home Assistant.
5月 16 23:47:10 xiaopan systemd[1603]: [email protected]: Failed to execute command: P>
5月 16 23:47:10 xiaopan systemd[1603]: [email protected]: Failed at step EXEC spawning>
5月 16 23:47:10 xiaopan systemd[1]: [email protected]: Main process exited, code=exite>
5月 16 23:47:10 xiaopan systemd[1]: [email protected]: Failed with result 'exit-code'.
lines 1-11/11 (END)

Can you please post your service file, something looks wrong.
This is most certainly not “execuatble” —

ExecStart=/srv/homeassistant

There is no command there

How to obtain service files

Did you create a file called “[email protected]” in your “/etc/systemd/system/” directory? Of course you did … it clearly says in the output:

Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: en>

Send the contents of that file

Yes, that’s right

I don’t know how to upload it. I’ve made it a link
http://download.stardreams.top:88/[email protected]

Well something does not look right. Certainly that should do a “cd” to /srv/homeassistant

Please post the output of this command:

sudo systemctl show home-assistant@homeassistant

That file should say:

ExecStart={ path=/srv/homeassistant/bin/hass ; argv[]=/srv/homeassistant/bin/hass -c /home/homeassistant/.homeassistant ; ignore_errors=no ; start_time=[Mon 2022-05->
ExecStartEx={ path=/srv/homeassistant/bin/hass ; argv[]=/srv/homeassistant/bin/hass -c /home/homeassistant/.homeassistant ; flags= ; start_time=[Mon 2022-05-16 10:52>

If you are trying to run other commands and not showing your real service, then that was wrong.
If you made the service file wrong and are not reloading it (like you actually put in commands like source bin/activate) … this is why it is not functioning correctly.

Where is this written

Is is in the output of the command I told you to run.
It is likely that you tried to create some service that was probably doing what you did by hand:

cd /srv/homeassistant &&
source bin/activate &&
hass

This is not correct. You have then installed that service and then you sent/posted changes you made to the service file BUT you have not unloaded or reloaded that (old, incorrect) service.

Just changing the service file does not change anything. You need to follow the directions in that thread above where you posted the link otherwise no one can help you.

There is only one command your service should run …

/srv/homeassistant/bin/hass -c /home/homeassistant/.homeassistant

Period. Nothing else. And that would use “%i” to represent “homeassistant” which is the user and also where homeassistant is installed.

Start over. If the changes you state above are truly in your service file, then:

Step 1, run:

sudo systemctl --system daemon-reload

Step 2, run:

sudo systemctl start home-assistant@homeassistant

Step 3, check if it starts. If all is now OK, then run:

sudo systemctl enable home-assistant@homeassistant

This place shows this

ExecStart={ path=/srv/homeassistant ; argv[]=/srv/homeassistant && source bin/activate && hass ; ignore_er>
ExecStartEx={ path=/srv/homeassistant ; argv[]=/srv/homeassistant && source bin/activate && hass ; flags= >

Maybe the core installation method is not the best approach to begin with. Have you considered other methods? Any reason you’d have to do HA core method?

1 Like