InfluxDB after reboot

Hi. When I reboot my Raspberry Pi 2, the influxdb component not load corretrly. I get feedback with “Error during setup of component influxdb Traceback (most recent call last):” and I have to restart my HA from web, then all is ok. I have newest HA and newest influxdb. My configuration.yaml is for localhoast and that’s all. If anyone had such a problem?

Anyone have similar problem?

all the time . . .

Is your Influxdb on the same host as home assistant? Could be either the ethernet service, if remote, or the Influxdb service, if local, not being available when home assistant is starting, since you experience problem at RPi reboot.

Yes, Influx is on the same host. Therefore how can I delay scanning for influxdb in HA?

In principle, systemd should take care of that if you declare in the homeassistant.service file that it is dependent upon Influxdb service.

However, I don’t know the details of setting it up.

I haven’t noticed a problem myself, but I don’t restart the PI very often.

See this post on how to make sure mosquitto is started before hass service if using systemd:

Of course you have to adapt it for Influxdb.

Is this working for you? I’m currently facing the same issue and already have tried different systemd unit setting but somehow I keep getting the timeout error on the InfluxDB component, when rebootung my RPi. After just restarting the HA service then, everything is fine, so it definitely is an timing issue.

Here is my current (I also tried influx in the after section) approach - more home-assistant.service

Description=Home Assistant

and - more influxd.service

# If you modify this, please also make sure to edit

Description=InfluxDB is an open-source, distributed, time series database

Any ideas why I keep on having the issue, that Influx is not there when the HA component wants to access it?

I believe that I found a failproof solution to this issue. By combining information from systemd service should “wait” until influxdb has finished starting up and Wait for a port to be listening in Salt, I came up with the following:

  1. Create a /etc/systemd/system/influxdb.service.d folder.

  2. Inside this folder, create <any-name>.conf file. In my case I named it wait-for-socket.conf.

  3. Add the following code to the file (be sure to replace 8086 with your port if you run InfluxDB on a different one):

    ExecStartPost=/bin/sh -c 'until nc -z localhost 8086; do sleep 0.2; done'
  4. Run systemctl daemon-reload.

What will now happen is: after starting influxd, systemd will execute ExecStartPost command which will poll InfluxDB port and exit only after influxd starts listening on it. As homeassistant.service depends on influxdb.service, systemd won’t start Home Assistant until ExecStartPost command exists. So now when Home Assistant starts, InfluxDB should always be ready for incoming connections.

For the sake of completeness, my homeassistant.service looks like this:

Description=Home Assistant influxdb.service



Also using influxdb as database for home assistant, based on hassio docker containers. So if you want to stay within the standard solution and dont want to hack the root docker host of hassio, what could be the solution to delay the start of home assistant until influxdb is ready. If you would wait there forever, it is also bad, because you will not be able to access the web portal to manager your instance at all. Any ideas?

1 Like

Waiting is more of workaround - not ideal. You not necessary run them all on the same host.
If home assistant would just keep trying to reach external databases (infludDB, grafana) instead of giving up - that would be better solution.

I have a similar problem. My Inluxdb lives in a partially sleeping macmini. During normal operations, the database works just fine. No feeds are lost when I query them. But if my rapsbery pi HASSIO reboots, the influxDB connection is lost. I need to actively power up the macmini, then restart home assistant, and then it starts working back again. I could not try @leppa 's solution as I am under HASSIO. Any suggestions?