0

I have followed various tutorials to get systemd to launch Homebridge on my Pi. This is the main one which seems to have worked for many others: https://timleland.com/setup-homebridge-to-start-on-bootup/

When my Pi boots, running top etc doesn't show that the process is running. Upon asking for the status, I can see a chunk of Homebridge's log which indicates something has gone wrong.

pi@raspberrypi:/var/log $ systemctl status homebridge
● homebridge.service - Node.js HomeKit Server
   Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-01-12 14:10:22 AEDT; 5min ago
 Main PID: 289 (homebridge)
   CGroup: /system.slice/homebridge.service
           └─289 homebridge

Jan 12 14:10:29 raspberrypi homebridge[289]:   syscall: 'getaddrinfo',
Jan 12 14:10:29 raspberrypi homebridge[289]:   hostname: 'my.tado.com',
Jan 12 14:10:29 raspberrypi homebridge[289]:   host: 'my.tado.com',
Jan 12 14:10:29 raspberrypi homebridge[289]:   port: 443 }
Jan 12 14:10:29 raspberrypi homebridge[289]: [1/12/2019, 2:10:29 PM] [Tado AC] XXX - Error Getting Temperature Unit - XXX
Jan 12 14:10:29 raspberrypi homebridge[289]: [1/12/2019, 2:10:29 PM] [Tado AC] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Jan 12 14:10:29 raspberrypi homebridge[289]: [1/12/2019, 2:10:29 PM] [Tado AC] Can't finish Tado Installation
Jan 12 14:10:29 raspberrypi homebridge[289]: [1/12/2019, 2:10:29 PM] [Tado AC] Please check you config and restart homebridge
Jan 12 14:10:29 raspberrypi homebridge[289]: [1/12/2019, 2:10:29 PM] [Tado AC] If the problem persist, plese open Issue at https://github.com/nitaybz/homebridge-tado-ac/issues
Jan 12 14:10:29 raspberrypi homebridge[289]: [1/12/2019, 2:10:29 PM] [Tado AC] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The strange part for me is, when I start the process myself, the errors go away and Homebridge starts as expected.

$ sudo systemctl start homebridge

When I run systemctl cat homebridge.service, I get the contents of my service file:

pi@raspberrypi:/var/homebridge $ systemctl cat homebridge.service
# /etc/systemd/system/homebridge.service
[Unit]
Description=Node.js HomeKit Server 
After=syslog.target network-online.target

[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target

Does anyone have any suggestions as to what might be different in the boot scenario?

New contributor
Ricky is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Please edit your question and add the output of this command: systemctl cat homebridge.service. – Ingo Jan 12 at 12:37
  • @Ingo Edited, thanks. – Ricky Jan 12 at 22:20
0

So I was wrong. systemctl was actually launching my service, it was just too early. It seems obvious now, but the issue was that there was no active internet connection ready in order for the executable to run properly.

Even though my Homebridge service file specified network-online.target in After, it was being started before an internet connection came up. I tried a whole spread of different suggestions on how to hold off on starting my service until the right time, but nothing ended up working.

I ended up making my own shell script to wait for an active connection to come live.

#!/bin/sh
echo "Commencing access lock..."

result=0
alt_fault=""
while [ $result -eq 0 ] 
do
    case "$(curl -s --max-time 2 -I http://google.com | sed 's/^[^ ]*  *\([0-9]\).*/\1/; 1q')" in
        [23]) echo "HTTP connectivity is up"; result=1;;
        5) alt_fault="The web proxy won't let us through";;
        *) alt_fault="The network is down or very slow";;
    esac
done

echo "Obtained connection"

I then added this script as a pre script to my service, by changing my service file to look like this. Note the one change.

[Unit]
Description=Node.js HomeKit Server 
After=syslog.target network-online.target

[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge

ExecStartPre=/tado_internet_test.sh

ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target

The service is now appropriately delayed until the script returns, meaning we have an active internet connection.

New contributor
Ricky is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Ricky is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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