Skip to content

Instantly share code, notes, and snippets.

@houtianze
Forked from johannrichard/homebridge
Last active April 23, 2019 13:59
Show Gist options
  • Save houtianze/95987f50d9c9fe1d384ebd9c4eafcaa3 to your computer and use it in GitHub Desktop.
Save houtianze/95987f50d9c9fe1d384ebd9c4eafcaa3 to your computer and use it in GitHub Desktop.
Systemd Service for homebridge (http://github.com/nfarina/homebridge)
# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /var/lib/homebridge
# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*
[Unit]
Description=Node.js HomeKit Server
After=syslog.target network-online.target
[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
# Adapt this to your specific setup (could be /usr/bin/homebridge)
# See comments below for more information
#ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target

From: https://timleland.com/setup-homebridge-to-start-on-bootup/

  1. The location of my homebridge binary. Step 2
  2. Permissions were not correct and the service failed to load. Step 7
  3. I needed the persist folder in /var/homebridge directory. Step 6
#sudo nano /etc/default/homebridge and paste this gist
#sudo nano /etc/systemd/system/homebridge.service and paste this gist
#I had to remove local from:  ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS  because my homebridge installed in /usr/bin/
#Create a user to run service:
sudo useradd --system homebridge
sudo mkdir -p /var/lib/homebridge
sudo cp ~/.homebridge/config.json /var/lib/homebridge/
#This copies your current user’s config. This assumes you have already added accessories etc.
sudo cp -r ~/.homebridge/persist /var/lib/homebridge
sudo chmod -R 0777 /var/lib/homebridge
sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge
systemctl status homebridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment