RasPi AIO new install: runs ok from venv/bin/hass, fails from systemd start

New AIO venv install (repo version as on 2017-03-27) onto a fresh RaspPi Jessie PIXEL.


  1. When started this way as user pi:

source /srv/homeassistant/homeassistant_venv/bin/activate
hass

127.0.0.1:8123 serves a page that says Welcome Home! All seems ok, except that I have not yet configured any devices/sensors/etc. The map does not match the lat/longs but my actual problem is much bigger than this.

ps -uax shows that the process is run by user pi and the process is

pi .... ...python3 ...bin/hass

(i.e., no -c …)


  1. when user pi sets up home-assistant.service etc as systemd auto start, the process can be started and stopped by

sudo systemctl start home-assistant.service
sudo systemctl stop home-assistant.service

the relevant part in home-assistant.service is:

[Service]
Type=simple
User=homeassistant
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c /home/homeassistant/.homeassistant

(in the above the paths are fine and present on the RasPi as shown)

Then 127.0.0.1:8123 serves a page that shows the house logo and asks for a password, not reacting to any password. So no login or entry possible.

ps -uax shows that the process is run by user homeassistant and the process is

homeassistant .... ...python3 ...bin/hass -c ....

I tried changing home-assistant.service to start exec without the -c… part, but it made no difference.


  1. so now I change the user in home-assistant.service file from homeassistant to pi

[Service]
Type=simple
User=pi
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c /home/homeassistant/.homeassistant

When started, ps -uax shows the task running with pi as owner.
Then 127.0.0.1:8123 still serves a page that shows the house logo and asks for a password, not reacting to any password. So no login or entry possible.


So the ways of starting I played with are as follows:

  1. venv-based hass commandline execution: user is pi and the 127.0.0.1:8123 display works fine.
  2. systemd-based start: user is homeassistant, and the 127.0.0.1:8123display asks for login - it fails.
  3. systemd-based start: user is pi, and the 127.0.0.1:8123display asks for login - it fails.

So no matter how I try to set up the systemd service, the process does not render a working welcome page, whereas if I start tit manually everything appears to be fine.

When started on the commandline from within the venv is works fine.

How can I get the systemd service going?

In home-assistant.service is the line User=pi correct or should it be User=%i? what does the %i mean?

It seems that the homeassistant user is supposed to be a system user with no /home/* directory, but yet, there is such a directory. This /home/homeassistant/ directory was created as part of the AiO installation, I did not do any setup of any kind other than running the AiO script.

I must say the plethora of instructions that are all slightly different and apply to different installation approaches is very confusing and contradictory. Perhaps the authorities must find a way to colour code or otherwise differentiate between the different approaches to make it easier for newcomers like me.

Please, don’t just refer me to the doc pages, been there, done (most of) it.

1 Like

My service file looks like so:
````
[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=haemish
ExecStart=/usr/bin/python3 -m homeassistant
[Install]
WantedBy=multi-user.target
I don't seem to have a problem starting at startup.

Am I correct in saying, from the post, that you are able to start the service using the systemctl start and stop commands. If that is the case, considering the amount of time the raspberry pi takes to start its network stack is it not that these are not ready when HA starts. Are you including `After=network.target` in the service file.

Your point 1) also suggests that you're running HA from a virtual env on the pi....how do you activate the venv from the system service file?

These are probably not helpful suggestions since I am sure it has all already occurred to you. Consider it my two cents.

You still need to activate the virtual environment when starting through systemd. Adding the following line into the Service section should do that:

ExecStartPre source /srv/homeassistant/homeassistant_venv/bin/activate

(I don’t use the AiO installer, nor Raspberry Pi, but instead Ubuntu 16.04 on an x86 server, however, I’m expecting that the above should be similar on both platforms.)

In the line User=%i? the %i is being replaced with the username that is specified in the filename. If you want to run HA as user homeassistant, call the file [email protected]. The part after the @ is the username.

Haemish / exxamalte, thanks for your replies! I appreciate your reading the long post :slight_smile:

The matter is now fixed, it works as advertised. In my first installation I did not activate SSH before booting for the first time. Halfway through the first installation it stopped and I had to activate SSH before the second installation completed. I believe that something went wrong in this process.

Last night I reflashed the SD card with a clean raspbian, activated SSH just after flashing (still in my PC): you add an empty file named ‘ssh’ into the root of the flash disk. When raspbian boots for the first time, it will then activate SSH. After booting in the raspi, I then installed the All-in-One using this: https://home-assistant.io/docs/installation/raspberry-pi-all-in-one/. All seemed to have gone well, this morning I have a properly working HA!

I put in a pull request that a statement to this effect be added to the above instruction, and I see this morning that the instruction is now present in the page.

FYI, there is the home-assistant.service file contents:

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

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

[Install]
WantedBy=multi-user.target

The above service file is present here /etc/systemd/system/home-assistant.service, with a symbolic link to this file here /etc/systemd/system/multi-user.target.wants/home-assistant.service

thanks for your time!

1 Like

NelisW
what is the file extension of the SSH file you created in the root directory?

which Raspbian Jessie did you use
Raspbian Jessie with PIXEL or Raspbian Jessie Lite.

Did you us the

$ curl -O https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/hass_rpi_installer.sh && sudo chown pi:pi hass_rpi_installer.sh && bash hass_rpi_installer.sh

command to install

Hi ramdisk

I used a full Raspbian Jessie PIXEL image (which contains a lot of other useless apps like Wolfram, games, etc.) but it does install a full X11 Window system, so you have a nice GUI (the PIXEL desktop). The other Raspbian option is the Lite version, a lot smaller, but there is no X11, so it is more suited to ‘headless’ operation which means that you have to connect from another PC.
http://www.circuitbasics.com/raspberry-pi-basics-setup-without-monitor-keyboard-headless-mode/
https://www.raspberrypi.org/forums/viewtopic.php?t=157896&p=1027355

BTW, after installing Raspbian PIXEL and HA, more than 6 GB of the SD card is used up - less than 2 GB left on a 8GB card! So get at least a 16GB card if you want to do anything else on the RaspPi.

The ssh file was written in Windows just after I wrote the SD card (using https://etcher.io/). While the SD card was still in the Windows PC I created a new file in the root of the card, with the name ‘ssh’ - lower case letters and no extension. The file was also empty. I guess the mere presence of this file in the root (which is also seems to be the Raspbian /boot/ ??) is a flag to signal to Raspbian that SSH must be activated. Here is the RasPi page on SSH at boot:

You can also activate SSH later after the initial boot in Raspbian, however, I do believe you MUST do this before the AiO HA install. I am not sure if there are any other secondary activations after the initial SSH activation at initial boot. So better to do it even before you boot up Raspbian for the first time.

I followed the procedure described here (which seems to be the one you refer to):


It creates a virtual environment and then installs HA to this virtual environment. I use virtual environments a lot in Python and it works very nicely to separate installation requirements for different versions of Python or different applications.

good luck!

NelisW

Thank you very much, I will be giving this a try this evening…

Great NEW the All-In-One installer worked.
I even rebooted my PI 3 and HA was there, and my 7" display is also working

Thanks NelisW