Setup Homebridge to start via systemd to automatically restart Homebridge after crashes. After successfully installing Homebridge on Raspberry Pi, it often happens that Homebridge stops running and you have to manually press plugin auto repair in the Homebridge app and reboot the Homebridge service. By Setting up Homebridge to start via systemd, there is no need of manually reboot Homebridge or make any plugin auto repair via the iOS Homebridge app. The systemd method is the preferred ones because it will restart if an error occurs.
iOS Homebridge app is an ease of use for connecting non-certified HomeKit devices to HomeKit.
Raspberry Pi: How to set up Homebridge on Bootup via systemd
- Open Terminal SSH.
sudo nano /etc/default/homebridge
and paste this gistsudo nano /etc/systemd/system/homebridge.service
and paste this gist- Maybe you need to remove local from:
ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
because your Homebridge is installed in /usr/bin/
- Maybe you need to remove local from:
- Create a user to run service:
sudo useradd --system homebridge
- Type
sudo mkdir /var/homebridge
- Type
sudo cp /root/.homebridge/config.json /var/homebridge/
- This copies your current user’s config. This assumes you have already added accessories etc.
- Depending where the directory is you need to type:
sudo cp ~/.homebridge/config.json /var/homebridge/
- Type
sudo cp -r /root/.homebridge/persist /var/homebridge
- Depending where the directory is you need to type:
sudo cp -r ~/.homebridge/persist /var/homebridge
- Depending where the directory is you need to type:
- Type
sudo chmod -R 0777 /var/homebridge
- Type
sudo systemctl daemon-reload
- Type
sudo systemctl enable homebridge
- Type
sudo systemctl start homebridge
- Type
systemctl status homebridge
to check the status of the service. - Type
sudo reboot
Notes:
- Systems can also be activated in the iOS Homebridge app via. However, it looks like this way is not as good as activating systemd via ssh shell.
- I successfully tested systemd on a Raspberry Pi Model 3 B+ and a Raspberry Pi 3 Model B.
Setup Homebridge to start on bootup via systemd to tackle Homebridge crashes and instability. These issues can be fixed by activating systemd via SSH shell commands. This option does not fix the rude cause, but keeps Homebridge automatically restarting and working after crashes.
Stay tuned! 😉