Skip to content

How To Swap From Standalone Mode to Service Mode

oznu edited this page Aug 23, 2020 · 4 revisions

This article describes how to swap from the depreciated Standalone Mode to "service" using the provided hb-service command.

Advantages of Service Mode

Users running under hb-service retain the same advantages of the depreciated Standalone Mode:

✔️   The UI remains online even if Homebridge is crashing due to a config error
✔️   Automatic start on boot
✔️   Automatic restart if Homebridge crashes

In addition, running in service mode (hb-service) provides many advantages to running in Standalone Mode:

✔️   Automatic creation of the systemd unit file
✔️   A single service file for both Homebridge and the Homebridge UI
✔️   Homebridge UI settings are pre-configured (you don't have to configure the log view etc.)
✔️   Persistent logs with automatic log rotation
✔️   The ability to download and truncate the log file from the Homebridge UI
✔️   Automated creation of default config.json and storage folders
✔️   Syntax validation and repair of the Homebridge config.json on start
✔️   The ability to clear the Homebridge accessory cache from the UI
✔️   The ability to remove selected accessories from Homebridge accessory cache from the UI
✔️   The ability to set the Homebridge -D debug, -K keep orphans, and -I insecure mode flags from the Homebridge UI
✔️   The ability to set the DEBUG and NODE_OPTIONS environment variables from the UI

How To Migrate To Service Mode

Remove the homebridge-config-ui-x service:

sudo systemctl stop homebridge-config-ui-x
sudo systemctl disable homebridge-config-ui-x
sudo rm -rf /etc/systemd/system/homebridge-config-ui-x.service

Remove the homebridge service:

sudo systemctl stop homebridge
sudo systemctl disable homebridge
sudo rm -rf /etc/systemd/system/homebridge.service

Use hb-service to create the new service file:

sudo hb-service install --user homebridge --port 8080 -U /var/lib/homebridge
  • --user: the user account homebridge should run as, if it does not exist it will be created.
  • --port: the port the UI should run on.
  • -U: the Homebridge storage directory, if it does not exist it will be created with the default config.json pre-configured.

That's it. You should be back up and running in "Service Mode". The hb-service utility provides many useful commands for managing Homebridge from the command line, see the Homebridge Service Command wiki page for futher details.

Multiple Instances

hb-service makes it easy to run multiple instances. See the Multiple Instances section of the Service Command wiki page.

sudo hb-service install --user homebridge --port 8081 --service-name homebridge-two -U /var/lib/homebridge-two 

Docker

If you are running in Docker, you can migrate to "Service Mode" by pulling down the latest version of the oznu/homebridge Docker image.

Clone this wiki locally