0% found this document useful (0 votes)
263 views19 pages

Autostart Using Systemd - Community Guides - Home Assistant Community

Autostart Using Systemd - Community Guides - Home Assistant Community

Uploaded by

faszomjoska23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
263 views19 pages

Autostart Using Systemd - Community Guides - Home Assistant Community

Autostart Using Systemd - Community Guides - Home Assistant Community

Uploaded by

faszomjoska23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

Autostart using systemd


installation

system (system) 1 May 26, 2020, 2:58pm

Newer Linux distributions are trending towards using systemd for managing daemons. Typically, systems
based on Fedora, ArchLinux, or Debian (8 or later) use systemd. This includes Ubuntu releases including and
after 15.04, CentOS, and Red Hat. If you are unsure if your system is using systemd, you may check with the
following command:

ps -p 1 -o comm=

If the preceding command returns the string systemd, continue with the instructions below.

A service file is needed to control Home Assistant with systemd. The template below should be created using
a text editor. Note, root permissions via sudo will likely be needed. The following should be noted to modify
the template:

ExecStart contains the path to hass and this may vary. Check with whereis hass for the location.

For most systems, the file is /etc/systemd/system/home-assistant@YOUR_USER.service with


YOUR_USER replaced by the user account that Home Assistant will run as (normally homeassistant).

If unfamiliar with command-line text editors, sudo nano -w [filename] can be used with
[filename] replaced with the full path to the file. Ex. sudo nano -w /etc/systemd/system/home-
assistant@YOUR_USER.service. After text entered, press CTRL-X then press Y to save and exit.

Python virtual environment


If you’ve setup Home Assistant in virtualenv following our manual installation guide for Raspberry Pi
(or the Python installation guide), the following template should work for you. If Home Assistant install is not
located at /srv/homeassistant, please modify the ExecStart= line appropriately. YOUR_USER should be
replaced by the user account that Home Assistant will run as (e.g homeassistant).

The file will be called /etc/systemd/system/home-assistant@YOUR_USER.service

[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

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 1/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

[Install]
WantedBy=multi-user.target

Now head down to the Next Steps section

Docker
If you want to use Docker, the following template should work for you.

[Unit]
Description=Home Assistant
Requires=docker.service
After=docker.service

[Service]
Restart=always
RestartSec=3
ExecStart=/usr/bin/docker run --name=home-assistant-%i -v /home/%i/.homeassistant
ExecStop=/usr/bin/docker stop -t 2 home-assistant-%i
ExecStopPost=/usr/bin/docker rm -f home-assistant-%i

[Install]
WantedBy=multi-user.target

Next Steps
You need to reload systemd to make the daemon aware of the new configuration.

sudo systemctl --system daemon-reload

To have Home Assistant start automatically at boot, enable the service.

sudo systemctl enable home-assistant@YOUR_USER

To disable the automatic start, use this command.

sudo systemctl disable home-assistant@YOUR_USER

To start Home Assistant now, use this command.

sudo systemctl start home-assistant@YOUR_USER

You can also substitute the start above with stop to stop Home Assistant, restart to restart Home
Assistant, and ‘status’ to see a brief status report as seen below.

$ sudo systemctl status home-assistant@YOUR_USER


● [email protected] - Home Assistant for YOUR_USER

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 2/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

Loaded: loaded (/etc/systemd/system/home-assistant@YOUR_USER.service; enabled; ve


Active: active (running) since Sat 2016-03-26 12:26:06 CET; 13min ago
Main PID: 30422 (hass)
CGroup: /system.slice/system-home\x2dassistant.slice/home-assistant@YOUR_USER.ser
├─30422 /usr/bin/python3 /usr/bin/hass
└─30426 /usr/bin/python3 /usr/bin/hass
[...]

To get Home Assistant’s logging output, simple use journalctl.

sudo journalctl -f -u home-assistant@YOUR_USER

Because the log can scroll quite quickly, you can select to view only the error lines:

sudo journalctl -f -u home-assistant@YOUR_USER | grep -i 'error'

When working on Home Assistant, you can easily restart the system and then watch the log output by
combining the above commands using &&

sudo systemctl restart home-assistant@YOUR_USER && sudo journalctl -f -u home-ass

Automatically restarting Home Assistant on failure


If you want to restart the Home Assistant service automatically after a crash, add the following lines to the
[Service] section of your unit file:

Restart=on-failure
RestartSec=5s

21 Likes

Password to start HA in SSH

Where is homeassistant hiding?

Installing Home Assistant Core on CentOS/RHEL

Hassio transformed in home assistant

Auto-start on Raspberry pi

Home Assistant Installation

Installing Home Assistant Core on Fedora

Password for hass

Updating HA in venv, I'm missing something here

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 3/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

Autostart using init.d

Ubuntu Startup Script Script

Autostart Home Assistant on raspbian

How to start HA if Raspberry PI is rebooted

Manual SSH to AsusWrt works but HASS can't connect

Basic setup

Announcement: HADashboard v2 Beta3!

Autostart for manual installation method (Virtual Environment)

Unable to autostart homeassistant on RPI3

Autostarting home assistant on rPi - launch on reboot pauses at login page

How to autostart HASS in virtualenv?

Set a delay for HASS to Start After Server Restart (systemd)

Simplest way to start after Manual Hass install on RasPi

Wink/network issues... Stumped... Help!

Everything broken in 0.50.x

Hass.io RPI and RTC ds3231

Installing Home Assistant Supervised using Debian 12

Auto start HA would be error,but manual won't

Can't startup HA again or auto run or install HACS

Service is killed when restart GUI

Installing Home Assistant Supervised using Debian 12

HA Core won't start at boot, but does manually

How to start HA, won't restart

Missing "--pid-file path_to_pid_file" and "--daemon" options form my init service

How to start the home assistant core automatically

Installing Home Assistant Core 2023.2.2 in a Python vEnv on Raspberry Pi 3B+ step by step

I'm really looking forward to the launch of hass I've been waiting a very long time for the launch is this
normal?

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 4/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

Stuck in Python prerequisite loop

How to stop home assistant on the command line?

Forgot user and password of UI

How Home Assistant Core works

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:


unable to get local issuer certificate

Hass.os should be USB bootable on Raspberry Pi 3B, 3B+, 4B

Autorestart of HA on reboot

Installing Home Assistant Supervised using Debian 12

Help to configure Home Assistant on Rasbian!

HA is still using old home dir after move to new homedir

Issues configuring autostart

0.1088 problems

Failure To Launch - New Install of Hassio

HA auto start on failing

HA Stops about every 2nd day - RPi2 (SSH = ok)

Power cut kills Hassio - any fix while away from machine?

Auto start hass.io

Custom Component: systemd (Run HA as a systemd notify daemon, with watchdog support!)

How come I have to run these commands to start the Home Assistant?

Installing HA v0.41.0 in virtualenvt not create hass file for autostart using systemd

Template for home-assistant@[your user].service

Unable to get hassio tab on Web UI by running home assistant in python virtual environment

I need help, please

Autostart new install

Cannot get hass service to work (linux / systemd)

Help, upgrade to Stretch broke my homeassistant

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 5/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

publowpicasso (publow picasso) 2 July 21, 2020, 9:38am

Thanks good explanation got it working.

Advice to everyone new to Raspberry OS / linux.

Use “sudo nano” to sudo edit text files.


It’s harder to start but easier in the end because gksudo & other sudo methods to gui edit text files are hard to
get working now in latest versions of Linux

lsaranto (Lasse) 3 August 4, 2020, 7:09pm

Thank you for this! These steps should absolutely be included in the manual installation guide. Or at least
include a link to this post.

2 Likes

tfmeier (Thomas Meier) 4 September 4, 2020, 11:27pm

Thanks for the guide. Home Assistant doesn’t start and I believe it has got to do with the folder structure.
Here’s the output for sudo systemctl status home-assistant@homeassistant

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


Active: failed (Result: exit-code) since Fri 2020-09-04 19:18:58 EDT; 3min 15s
Process: 5409 ExecStart=/opt/homeassistant/bin/hass -c /home/%i/.homeassistant
Main PID: 5409 (code=exited, status=200/CHDIR)

Sep 04 19:18:58 vortexbox systemd[1]: Started Home Assistant.


Sep 04 19:18:58 vortexbox systemd[1]: [email protected]: Main process exited, cod
Sep 04 19:18:58 vortexbox systemd[1]: [email protected]: Unit entered failed stat
Sep 04 19:18:58 vortexbox systemd[1]: [email protected]: Failed with result 'exit

I have confirmed the Home Assistant install with whereis hass so I believe this is correct

Bartem 5 September 5, 2020, 12:01am

what does your systemd service file look like?

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 6/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

tfmeier (Thomas Meier) 6 September 5, 2020, 2:07am

system:

sudo systemctl start home-assistant@

As in /etc/systemd/system/home-assistant@YOUR_USER.service

I have created a user homeassistant so created /etc/systemd/system/[email protected] as per the


above instructions for a virtual environment (setup done via Installing Home Assistant Core on Fedora) -
only change is the location of home assistant which I checked via whereis hass

Description=Home Assistant
After=network-online.target
[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/opt/homeassistant/bin/hass -c "/home/%i/.homeassistant"

[Install]
WantedBy=multi-user.target

File details as follows

-rwxr-xr-x 1 root root 238 Sep 4 18:53 /etc/systemd/system/[email protected] ```

1 Like

DarS 7 October 14, 2020, 7:47pm

Thanks for this great guide! It works perfect except … for locally executed command lines.
My HA is installed in Python virt.environment on Debian. I have a pretty simple CPUtemp sensor ( platform:
command_line) with
command: cat /sys/class/thermal/thermal_zone0/temp
This runs as expected when HA is manually invoked:

> sudo -u homeassistant -H -s


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

The CPU temperature is read periodically and then displayed in my GUI.

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 7/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

But today I implemented the ‘systemd’ script to autostart the HA and … I started to receive this strange error
message every minute:

hass[978]: /bin/sh: 1: cat: not found


hass[978]: ERROR (SyncWorker_1) [homeassistant.components.command_line] Command f

It looks like HA (run by systemd) is invoking the command line with sh shell and not bash. Why? What am I
doing wrong?
I already checked the passwd file for homeassistant user and it is correctly set to /bin/bash. How can I
troubleshoot this further?

DarS 8 October 16, 2020, 6:44am

Yeah, something strange, really…


I’ve added this extra line to home-assistant.service file to check what shell the Home Assistant is being started:

ExecStartPre=echo $SHELL >> /home/homeassistant/asa.txt

daemon.log showed an interesting result:

Oct 16 08:25:48 localhost systemd[1]: Stopped Home Assistant.


Oct 16 08:27:21 localhost systemd[1]: Reloading.
Oct 16 08:27:37 localhost systemd[1]: Starting Home Assistant...
Oct 16 08:27:37 localhost echo[24133]: /bin/bash >> /home/homeassistant/asa.txt
Oct 16 08:27:37 localhost systemd[1]: Started Home Assistant.
[...]
Oct 16 08:27:55 localhost hass[24134]: /bin/sh: 1: cat: not found
Oct 16 08:27:55 localhost hass[24134]: 2020-10-16 08:27:55 ERROR (SyncWorker_18)

Now I see that systemd works properly and starts Home Assistant from bash. But then, Home Assistant (for
unknown reason) fires its own command line scripts from (much limited) sh shell. Gosh, why?
Or more precisely, why this happen only when HA is autostarted by this systemd script?

Tips for shell_command and auto-deleting old snapshots

louloulepou 9 December 22, 2020, 12:51pm

I am facing the same issue with the same setup (HA installed in virtual environment) : when starting Home
Automation manually with hass, I can run shell_commands without issue.

But when starting with the autostart systemd script, the commands are not successfull. In my case I am trying to
send an infrared signal to my amp with ir-ctl and tried to send the command directly or via a script
https://community.home-assistant.io/t/autostart-using-systemd/199497/print 8/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

Dec 22 12:53:50 raspberrypi hass[13207]: 2020-12-22 12:53:50 ERROR (MainThread) [


Dec 22 13:10:17 raspberrypi hass[13207]: 2020-12-22 13:10:17 ERROR (MainThread) [
Dec 22 13:10:17 raspberrypi hass[13207]: NoneType: None

Have you found a correction for this issue?

Dave_J 10 December 26, 2020, 9:55pm

I’m having problems enabling the service. I installed in a python virtual environment.

Here’s the output of the systemctl status:

● [email protected] - Home Assistant


Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset:
Active: inactive (dead)

Dec 26 13:49:18 raspberrypi systemd[1]: /etc/systemd/system/[email protected]:8:

Hass won’t execute out of a command line in its directory. Which is consistent with my assumption that hass is
a python script.

How is the ExecStart supposed to work with a python script?

Thanks.

Dave_J 11 December 30, 2020, 6:46pm

Here’s my resolution:

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

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant

ExecStart=/home/pi/homeassistant/bin/python3 /home/pi/homeassistant/bin/hass

[Install]

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 9/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

WantedBy=multi-user.target

1 Like

SamWhiskey 12 January 6, 2021, 10:16pm

I am not an expert, but maybe I can help you:


Services started as daemons have a more limited environment than a normal console login.
There is no stdin and stdout available and the PATH variable is not the same.
So, whatever you do within a service, you should work with full pathnames or add the necessary pathes at the
beginning.

cyberom (Romain GUENEGOU) 13 January 12, 2021, 10:41am

Perfect guide !

was working on my PI3 with raspbian install.

I would suggest to add/integrate it on the Doc

Manual installation on a Raspberry Pi


Instructions to install Home Assistant Core on a Raspberry Pi running Raspberry
Pi OS Lite.

Thanks

DaveAtkNH (Dave H) 14 January 15, 2021, 3:04pm

Thanks for the guide. It worked great after a few modifications for my environment.

If your configuration uses a serial port for ZWave make sure that the HomeAssistant account in the systemctl
file has access, or the daemon will start but not be able to communicate with the ZWave devices. Here is a link
that explains Automatic ACL assignment at boot time. The HomeAssistat install scripts create the file
/etc/udev/rules.d/90-extraacl.rules. This file gives permission to the USB serial ports for the user that ran the
install scripts. If you run under a different user, the file will have to be edited to grant permission to that user.

Configure permissions for /dev/ttyUSB0


linux, permissions
https://community.home-assistant.io/t/autostart-using-systemd/199497/print 10/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

asked by Mike L. on 04:55PM - 02 Jun 12 UTC

KupieTools 15 February 13, 2021, 9:30am

The instructions ought to include that if you already had a working installation and you’re just trying to get
Docker to start HA automatically on boot (because, say, as in my case, it used to start automatically but no
longer does and you can’t figure out why), you have to change the path to the config folder from
/home/%i/.homeassistant/ to whatever your correct current config path is. Otherwise you start over with
a fresh blank config.

JohannCR (Johann) 16 February 16, 2021, 3:49pm

I second @KupieTools
Broke my entire install… Got a fresh HA without supervisor (don’t know why, but that’s problematic to restore
a snapshot…). I don’t know how I’m gonna get out if this one. I ought to be more careful doing stuff I don’t
know enough about ^^
Edit: Nevermind, I was lucky enough to give the wrong folder so I did not overwrite anything so all is well.
Beware if you’re not sure what you’re doing^^

aa755 (Aa755) 17 February 17, 2021, 6:55pm

if you have a component that accesses network at startup, After=network-online.target may not be
sufficient. In my case, dns resolution was failing for my component when it accessed network at startup,
probably because systemd was starting hass too early.
The following helped me: https://unix.stackexchange.com/a/356189/62292
My systemd file is:

[Unit]
Description=Home Assistant
After=NetworkManager-wait-online.service
Requires=NetworkManager-wait-online.service

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 11/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

[Install]

More info about my machine (standard Manjaro KDE)

[xxxxx@computer ~]$ systemctl is-enabled NetworkManager-wait-online.service syste


enabled
disabled

1 Like

MickPB (Jeff Mickens) 18 February 28, 2021, 9:54pm

Help please. After some system changes I find that I cannot get the Supervisor container to start after a reboot.

It starts fine if I trigger it manually.

I’ve checked /etc/systemd/system/hassio-supervisor.service

[Unit]
Description=Hass.io supervisor
Requires=docker.service
After=docker.service dbus.socket

[Service]
Type=simple
Restart=always
RestartSec=5s

ExecStartPre=-/usr/bin/docker stop hassio_supervisor


ExecStart=/usr/sbin/hassio-supervisor
ExecStop=-/usr/bin/docker stop hassio_supervisor

[Install]
WantedBy=multi-user.target

and tried
sudo systemctl daemon-reload

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 12/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

sudo systemctl restart

and
curl -Lo installer.sh https://raw.githubusercontent.com/home-assistant/supervised-
installer/master/installer.sh
bash installer.sh

But still end up having to start the supervisor container manually. I see other posts that indicate some portion of
the install might need to be re issued but have not been able to pick that apart and apply it to the current HA.
My enviro

core-2021.2.3
supervisor-2021.02.11
Docker 20.10.4
Raspbian GNU/Linux 10

TIA

1 Like

filgr8 (Filgr8) 19 March 1, 2021, 5:35pm

editing this file helped me with manual restarting HA

sudo nano /etc/systemd/system/hassio-supervisor.service

and editing this line to:


#ExecStartPre=-/usr/bin/docker stop hassio_supervisor

and

sudo systemctl --system daemon-reload

MickPB (Jeff Mickens) 20 March 1, 2021, 6:17pm

I have that in there already. Thanks though

Funny coincidence, Same time you sent that - I was just watching the system restart and for a bit Supervisor
was running and then fell over. I can restart the container and all is well>?>? Maybe there is another sequence
issue. I dunno. Very frustrate. This all started with trying out TailScaled in place of Wireguard

filgr8 (Filgr8) 21 March 1, 2021, 7:04pm

Did you put hashtag in front like iI did?

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 13/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

Hashtag “commenting out” help me with reboot

filgr8 (Filgr8) 22 March 1, 2021, 7:07pm

What triggered my problem with HA not starting up after reboot is Ubuntu apt upgrade/update

1 Like

belov-ve (Belov V) 23 March 2, 2021, 3:42pm

Same problem after Raspbian update (PI 3). In hassio-supervisor service container don’t start with key --attach
(in file /usr/sbin/hassio-supervisor last line with docker start --attach hassio_supervisor).
Docker version 20.10.4
Downgrading docker-ce to 19.03.15 did not help.
Everything worked on docker version 20.10.4 after reinstalling the Home Assistant Supervised:

home-assistant/supervised-installer
Installer for a generic Linux system. Contribute to home-assistant/supervised-installer
development by creating an account on GitHub.

MickPB (Jeff Mickens) 24 March 3, 2021, 1:47am

Thanks for pointing that out - iPhone doesn’t make up for me not wearing my glasses!
I’ll give that a try.

After trying it - No joy. I tried it a second time after re-running the installer as well

MickPB (Jeff Mickens) 25 March 3, 2021, 2:44am

Thanks all for the help.

I tried commenting the line and no joy. I tried re-running the install script no luck. Re-commented the line and
no luck. Finally read the log file and found a complaint regarding HACS having an invalid token. I tried
removing and reloading HACS and get the ever helpful “unknown error” when re-installing.

I’ve made too many mistakes trying changes and doing things to the system and now doubt that I can ever trust
it again. At this point I am still open for ideas but as soon as I get time I guess I will try rebuilding the system
and then recopying to the SSD.

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 14/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

If anyone has a guide to do that - I’d really appreciate a link


Thanks again

matbee (matbee) 26 December 9, 2021, 8:41am

The systemd setup works fine for me, however the audio messages played with aplay only work when started
from the terminal.
Here’s the test command: /usr/bin/aplay /usr/share/sounds/alsa/Front_Center.wav
It seems that aplay doesn’t have enough permissions.

How can investigate further?

dony1971 (Dony) 27 December 23, 2021, 10:27pm

I have problem also executing hass in virtualenv via systemd


Python SSL has ssl.SSLCertVerificationError via systemd
(ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
unable to get local issuer certificate)
Anybody know why?

Maschbaer 28 January 29, 2022, 10:42am

Hello,

I am running HA das Docker Container. I would like to start it via systemd at the start up of my Pi. It tried the
example above but it does not work for me. Instead I have the following service file which works to start the
HA Docker container manually by sudo systemctl start home-assistant-docker.service

The code of my service file is as follows:

[Unit]
Description=Home Assistant Docker
Requires=docker.service
After=docker.service

[Service]
Restart=always
RestartSec=3
ExecStart=/usr/bin/docker start -a home-assistant
ExecStartPre=/bin/sleep 40
ExecStop=/usr/bin/docker stop -t 2 home-assistant

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 15/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

[Install]
WantedBy=mutli-user.target

P.s.
It setup a sleep of 40, because I need to wait until my Homematic CCU, which is running on the same Pi, is
loaded, because HA reads some sensor data from the HM CCU.

However, even after doing sudo systemctl --system daemon-reload and sudo systemctl enable
home-assistant-docker.service the HA Docker Container does not start when I reboot my Pi.

Any suggestions what I do wrong?


Jan

Roumano (Roumano) 29 February 3, 2022, 7:53am

Hi,
It’s a breaking changed on the 2022.02.0 (not listed yet) with systemd.

Need to add this on a core home assistant systemd configuration :

RestartForceExitStatus=100

More information on the issue created :

Failed to restart Home Assistant with the Gui with the 2022.2.0 version
opened 09:40PM - 02 Feb 22 UTC closed 05:24AM - 03 Feb 22 UTC roumano

### The problem


After upgrading to `2022.2.0`, if i restart the home assistant …

1 Like

HelpITru (Help I Tru) 30 February 6, 2022, 2:58pm

does not work in HASS OS, it is generally impossible to run a python script in the background there.

joeyparis (Joey Paris) 31 February 14, 2022, 3:48am

I found my solution to getting this working again here. I had to run

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 16/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

systemctl enable systemd-networkd-wait-online.service

Then replaced After=network-online.target with:

[Unit]
...
After=systemd-networkd-wait-online.service
Requires=systemd-networkd-wait-online.service

From my understanding, Requires being a stricter version of Wants/WantedBy which is critical to running
this on boot.

1 Like

TallGayDani 32 March 13, 2022, 12:43pm

Hi, so I followed the instructions to a T, but fedora is throwing errors?


Here’s what’s come up:

Started Home Assistant.


[email protected]: Failed to locate executable /srv/homeassistant/bin/hass: No such file or directory
[email protected]: Failed at step EXEC spawning /srv/homeassistant/bin/hass: No such file or directory
[email protected]: Main process exited, code=exited, status=203/EXEC
[email protected]: Failed with result ‘exit-code’.

I checked HASS and it’s definitely locatable, what could I be doing wrong? TIA

planetmarshall (Andrew Marshall) 33 March 24, 2022, 12:02pm

system:

WorkingDirectory=/home/%i/.homeassistant

Very helpful thanks. Worth noting that if you are installing home assistant from scratch (eg using ansible or
some other method to automate an install), the .homeassistant folder does not exist, and starting the service
will fail.

The solution is just to create it before starting the service.

mkdir /home/YOUR_USER/.homeassistant
sudo systemctl start home-assistant@YOUR_USER

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 17/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

damiano94 (Damiano94) 35 July 5, 2023, 10:52pm

So when hass is started using systemd, there’s no need to enable virtualenv first?

glyndon 36 July 5, 2023, 11:14pm

You don’t need to have activated the venv for yourself, but whatever systemd calls, should do so for itself.
I’ve used a venv for many years to run HA, and have always launched it using a systemd .desktop file, which
calls a shell script, the first two lines of which are:

#!/bin/bash
. /srv/homeassistant/bin/activate

So even though systemd starts the HA process through the script, the script/process still sets itself up in the
venv, else who knows what python, packages, and environment HA might be inheriting!

dannysauer (Danny Sauer) 37 August 20, 2023, 4:27am

People probably shouldn’t directly edit systemd units in specific paths - it’s easy to make an error. To create
a new one:
systemctl edit --force --full [email protected]

To edit the main unit file:


systemctl edit --full [email protected]

To add an override:
systemctl edit [email protected]

There’s no need to remember which location is for user units or system units or for packager units or for
overrides, etc. Run it as a user, get a user unit. Run it as root, get a local system unit. It’ll even use whatever
you have set in $EDITOR or $VISUAL, so vim or nano or whatever. That also automatically does the daemon-
reload afterwards if necessary, so no forgetting to run that command. I really wish this was better publicized;
it’s sooo much more convenient.

3 Likes

b24home (b24home) 38 February 16, 2024, 3:18pm

Can anyone point me in the right direction to get HA running at boot for my rpi4, and to keep it running even
(i.e. restart on crash)? I am a total noob with all of this stuff and I’ve wasted hours to no avail.

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 18/19
9/13/24, 4:05 PM Autostart using systemd - Community Guides - Home Assistant Community

This was my install: Installing Home Assistant Supervised using Debian 12

kbrown01 (Kbrown01) 39 February 17, 2024, 7:39am

Did you read all the notes for that type of install listed at the top of the link? Especially the part that if you are a
total noob as you say, you shouldn’t attempt this? If you have a PI you should install the OS directly which has
nothing to do with Core and systemd to autostart. This question applies to Home Assistant Core installed on a
Linux OS

1 Like

https://community.home-assistant.io/t/autostart-using-systemd/199497/print 19/19

You might also like