-
-
Save johannrichard/0ad0de1feb6adb9eb61a to your computer and use it in GitHub Desktop.
# 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 | |
Restart=on-failure | |
RestartSec=10 | |
KillMode=process | |
[Install] | |
WantedBy=multi-user.target |
So, I wrote the homebridge.service again to avoid any unwanted CRs. But it does not work:
[root@DietPi:/etc/systemd/system# systemctl status homebridge
● homebridge.service - Node.js Homekit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: activating (auto-restart) (Result: exit-code) since Fr 2018-03-23 12:51:24 CET; 4s ago
Process: 4252 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
Main PID: 4252 (code=exited, status=1/FAILURE)
Mär 23 12:51:24 DietPi systemd[1]: Unit homebridge.service entered failed state.
Nobody?
I am running 3 instances of homebridge all started at boot using systemd.
Here are the contents of the the first homebridge.service script - located at /etc/systemd/system/. The only comment to share with you in relation to your file is - be careful running stuff as the root user. I use the root user - but my Debian Server is a Hyper-V Virtual Machine which is backed up daily hence recreating a Virtual Machine with no data loss is simple. Also some of the dynamically created folders, can appear in locations which differ from the relative tutorials:
====================================
[Unit]
Description=Node.js Homekit Server
After=syslog.target network-online.target
[Service]
Type=simple
User=root
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
===================================
Here is the contents of the first environment script, who's location is referenced in the service script above. I suggest moving the location of your homebridge conf.json file to a location which can be directly referenced - eg. /var/lib/homebridge - as referenced in the script below. On a Debian Server, I have never been successful in using '~/.somefolder' in service scripts and moving the script to the location suggested effectively addresses this. cp ~/.homebridge/config.json /var/lib/homebridge/config.json worked in my scenario.
===================================
# 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 -P /usr/lib/node_modules -I
===================================
Depending on how you installed - on what, the script paths could be different.
Now reload the systemd config, make sure the service is enabled (symlink created) and I would then reboot.
... once booted I check my homebridge.service - see below.
===================================
root@homebridge:/etc/default# sudo systemctl status homebridge.service
● homebridge.service - Node.js Homekit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2018-04-04 23:33:12 BST; 40min ago
Main PID: 875 (homebridge)
Tasks: 11 (limit: 19660)
CGroup: /system.slice/homebridge.service
└─875 homebridge
===================================
Hi, I´m quite new to Raspberry Pi etc and have a question. Homebridge works fine when I manually open it. This is the error log that happens when I try and do the above (autoload).
-- Logs begin at Fri 2016-11-04 07:16:43 +14, end at Mon 2018-05-14 16:35:45 +13. --
May 14 16:25:26 raspberrypi systemd[1]: Started Node.js HomeKit Server.
May 14 16:25:39 raspberrypi homebridge[403]: â<94><8C>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â
May 14 16:25:39 raspberrypi homebridge[403]: â<94><82> npm update check failed â<94><82>
May 14 16:25:39 raspberrypi homebridge[403]: â<94><82> Try running with sudo or get access â<94><82>
May 14 16:25:39 raspberrypi homebridge[403]: â<94><82> to the local update config store via â<94><82>
May 14 16:25:39 raspberrypi homebridge[403]: â<94><82> sudo chown -R
May 14 16:25:39 raspberrypi homebridge[403]: â<94><94>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â
May 14 16:25:45 raspberrypi homebridge[403]: [2018-5-14 16:25:45] Loaded plugin: homebridge-nest
May 14 16:25:45 raspberrypi homebridge[403]: [2018-5-14 16:25:45] Registering platform 'homebridge-nest.Nest'
May 14 16:25:45 raspberrypi homebridge[403]: [2018-5-14 16:25:45] ---
May 14 16:25:45 raspberrypi homebridge[403]: [2018-5-14 16:25:45] There was a problem reading your config.json file.
May 14 16:25:45 raspberrypi homebridge[403]: [2018-5-14 16:25:45] Please try pasting your config.json file here to validate it: http://jsonlint.co
May 14 16:25:45 raspberrypi homebridge[403]: [2018-5-14 16:25:45]
May 14 16:25:45 raspberrypi homebridge[403]: /usr/lib/node_modules/homebridge/lib/server.js:207
May 14 16:25:45 raspberrypi homebridge[403]: throw err;
May 14 16:25:45 raspberrypi systemd[1]: homebridge.service: Main process exited, code=exited, status=1/FAILURE
May 14 16:25:45 raspberrypi systemd[1]: homebridge.service: Unit entered failed state.
May 14 16:25:45 raspberrypi systemd[1]: homebridge.service: Failed with result 'exit-code'.
May 14 16:26:03 raspberrypi systemd[1]: homebridge.service: Service hold-off time over, scheduling restart.
May 14 16:26:03 raspberrypi systemd[1]: Stopped Node.js HomeKit Server.
May 14 16:26:03 raspberrypi systemd[1]: Started Node.js HomeKit Server.
May 14 16:26:05 raspberrypi homebridge[883]: â<94><8C>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â
May 14 16:26:05 raspberrypi homebridge[883]: â<94><82> npm update check failed â<94><82>
May 14 16:26:05 raspberrypi homebridge[883]: â<94><82> Try running with sudo or get access â<94><82>
May 14 16:26:05 raspberrypi homebridge[883]: â<94><82> to the local update config store via â<94><82>
May 14 16:26:05 raspberrypi homebridge[883]: â<94><82> sudo chown -R
May 14 16:26:05 raspberrypi homebridge[883]: â<94><94>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â
May 14 16:26:06 raspberrypi homebridge[883]: [2018-5-14 16:26:06] Loaded plugin: homebridge-nest
May 14 16:26:06 raspberrypi homebridge[883]: [2018-5-14 16:26:06] Registering platform 'homebridge-nest.Nest'
May 14 16:26:06 raspberrypi homebridge[883]: [2018-5-14 16:26:06] ---
May 14 16:26:06 raspberrypi homebridge[883]: [2018-5-14 16:26:06] There was a problem reading your config.json file.
May 14 16:26:06 raspberrypi homebridge[883]: [2018-5-14 16:26:06] Please try pasting your config.json file here to validate it: http://jsonlint.co
May 14 16:26:06 raspberrypi homebridge[883]: [2018-5-14 16:26:06]
May 14 16:26:06 raspberrypi systemd[1]: homebridge.service: Main process exited, code=exited, status=1/FAILURE
May 14 16:26:06 raspberrypi systemd[1]: homebridge.service: Unit entered failed state.
May 14 16:26:06 raspberrypi systemd[1]: homebridge.service: Failed with result 'exit-code'.
May 14 16:26:17 raspberrypi systemd[1]: homebridge.service: Service hold-off time over, scheduling restart.
May 14 16:26:17 raspberrypi systemd[1]: Stopped Node.js HomeKit Server.
May 14 16:26:17 raspberrypi systemd[1]: Started Node.js HomeKit Server.
May 14 16:26:19 raspberrypi homebridge[909]: â<94><8C>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â
May 14 16:26:19 raspberrypi homebridge[909]: â<94><82> npm update check failed â<94><82>
May 14 16:26:19 raspberrypi homebridge[909]: â<94><82> Try running with sudo or get access â<94><82>
May 14 16:26:19 raspberrypi homebridge[909]: â<94><82> to the local update config store via â<94><82>
May 14 16:26:19 raspberrypi homebridge[909]: â<94><82> sudo chown -R
May 14 16:26:19 raspberrypi homebridge[909]: â<94><94>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â<94><80>â
May 14 16:26:20 raspberrypi homebridge[909]: [2018-5-14 16:26:20] Loaded plugin: homebridge-nest
May 14 16:26:20 raspberrypi homebridge[909]: [2018-5-14 16:26:20] Registering platform 'homebridge-nest.Nest'
May 14 16:26:20 raspberrypi homebridge[909]: [2018-5-14 16:26:20] ---
May 14 16:26:20 raspberrypi homebridge[909]: [2018-5-14 16:26:20] There was a problem reading your config.json file.
May 14 16:26:20 raspberrypi homebridge[909]: [2018-5-14 16:26:20] Please try pasting your config.json file here to validate it: http://jsonlint.co
May 14 16:26:20 raspberrypi homebridge[909]: [2018-5-14 16:26:20]
May 14 16:26:20 raspberrypi homebridge[909]: /usr/lib/node_modules/homebridge/lib/server.js:207
Can someone please help me. That would be much appreciated!
Hi, I am new to all of this and having a bit of trouble. My homebridge seems to error out every few hours. I tried reinstalling everything from scratch and the problem occurs. I am interested in using automatic restart on error to help solve my problem. I am running into an issue when trying to drag the homebridge and homebroidge.service folders into their location. I get a permissions issue. I am sure I am missing a basic thing and would appreciate any help. Thanks!
@glk3504matic Use sudo pcmanfm
to open an elevated file explorer and then try to move the folders.
Anyone else run into the UUID issue?
Note: I intentionally left out the first few characters of the UUID
Error: Cannot add a bridged Accessory with the same UUID as another bridged Accessory: xxxxxxxx-xxxx-467d-b156-96cce88db05b May 16 16:09:10 piOnTheRange homebridge[638]: at Bridge.Accessory.addBridgedAccessory (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:257:13) May 16 16:09:10 piOnTheRange homebridge[638]: at Server._configCachedPlatformAccessories (/usr/lib/node_modules/homebridge/lib/server.js:348:18) May 16 16:09:10 piOnTheRange homebridge[638]: at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:83:8) May 16 16:09:10 piOnTheRange homebridge[638]: at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:40:10) May 16 16:09:10 piOnTheRange homebridge[638]: at Object.<anonymous> (/usr/lib/node_modules/homebridge/bin/homebridge:17:22) May 16 16:09:10 piOnTheRange homebridge[638]: at Module._compile (module.js:571:32) May 16 16:09:10 piOnTheRange homebridge[638]: at Object.Module._extensions..js (module.js:580:10) May 16 16:09:10 piOnTheRange homebridge[638]: at Module.load (module.js:488:32) May 16 16:09:10 piOnTheRange homebridge[638]: at tryModuleLoad (module.js:447:12)
@glk3504matic use journalctl -u homebridge
for a more detailed log. Also for your ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
in /etc/systemd/system/homebridge.service
try ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
instead.
@ddsforlife Your config.json
file is probably corrupt and violates JSON formatting. Use http://jsonlint.co like the error suggests to validate the contents of your config.json
file and then copy and paste the validated text back into the config.json
file.
I'm sorry. I don't understand where I'm messing up here. I get the following error.
sean@rock64:/etc/systemd/system$ systemctl status homebridge
● homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: resources) since Tue 2018-08-07 05:29:14 UTC; 3s ago
Aug 07 05:29:14 rock64 systemd[1]: homebridge.service: Failed to run 'start' task: No such file or directory
Aug 07 05:29:14 rock64 systemd[1]: Failed to start Node.js HomeKit Server.
Aug 07 05:29:14 rock64 systemd[1]: homebridge.service: Unit entered failed state.
Aug 07 05:29:14 rock64 systemd[1]: homebridge.service: Failed with result 'resources'.
Thanks so much for this tutorial, it was really helpful! The only thing I would like to add / clarify to the original post in the Configuration section are the following commands:
mkdir /var/lib/homebridge
(this creates the required directory that stores the config.json file in the modified located)
sudo chown -R homebridge:homebridge /var/lib/homebridge
sudo chmod 777 -R /var/lib/homebridge
(these commands set the permissions on the newly created folder, so that the homebridge user has the appropriate permissions)
The homebridge-harmonyhub plugin would not install globally so instead I tried installing node using nvm. It worked great. I was able to install homebridge and all plugins without needing root. I can invoke homebridge just fine from the command line, but when starting as a service it fails with this message -
homebridge[5072]: /usr/bin/env: ‘node’: No such file or directory
I have no idea where to begin with this one.
One of the plugins I'm attempting to use (Homebridge-dash) requires that Homebridge be run using evaluated permissions. I've setup the systemd service and all has worked fine for several months - but my question is this: does the systemctl start homebridge
command run at elevated permissions, and if not, how can I add sudo
to the the restart?
Note for systemd users: Your start service needs to start the NetworkManager-wait-online.service
before being able to wait after it is finished:
[Unit]
Description=Node.js HomeKit Server
Wants=network-online.target
After=syslog.target network-online.target
See https://unix.stackexchange.com/a/126146 for details.
I had the same problem as several have described, with "homebridge.service: Main process exited, code=exited, status=1/FAILURE". In my case, the issue was related to the homebridge-nukiio plugin not being able to start up without root access for some reason. I'm not sure why that was, especially since I had chowned and chmoded everything to homebridge with 0777 to be sure (the service itself, the /var/default/homebridge environment, /var/lib/homebridge/*, including persist and config.json - I do mean EVERYTHING), but, even though I know it's not best practice, once I switched to User: root in /var/systemd/system/homebridge.service everything started working. (User: pi didn't work either, in case anybody is wondering; removing nukiio from the platforms in config.json and running with User: homebridge worked just fine).
I have a same problem with nukiio on homebridge reboot !!!
How do we repair it ?
Thanks :-)
After trying million ways to get it work i finally, hopefully, managed to get rid of the "homebridge.service: Main process exited, code=exited, status=1/FAILURE". In the Homebridge defaults (etc/defaults/homebridge) you have to put HOMEBRIDGE_OPTS= the real config.json file folder. For me it was: HOMEBRIDGE_OPTS=-I -U /home/pi/.homebridge. Hope it helps!
I have a problem. The Homebridge can't find the config.json.
My /etc/systemd/system/homebridge.service is:
[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
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
The homebridge file is the same file with no changes.
When i try to run homebridge manually it works.
pi@piHomebridge:~ $ sudo su - homebridge
No directory, logging in with HOME=/
$ bash
homebridge@piHomebridge:/$ /usr/bin/homebridge -U /var/lib/homebridge
Output:
[7/3/2019, 20:48:38] Loaded config.json with 1 accessories and 0 platforms.
[7/3/2019, 20:48:38] ---
[7/3/2019, 20:48:38] Loaded plugin: homebridge-wol
[7/3/2019, 20:48:38] Registering accessory 'homebridge-wol.NetworkDevice'
[7/3/2019, 20:48:38] ---
[7/3/2019, 20:48:38] Loading 0 platforms...
[7/3/2019, 20:48:38] Loading 1 accessories...
The directory is okey
homebridge@piHomebridge:/$ ls -l /var/lib/homebridge/
total 12
drwxrwxrwx 2 homebridge homebridge 4096 Jul 3 18:29 accessories
-rwxrwxrwx 1 homebridge homebridge 460 Jul 3 20:01 config.json
drwxrwxrwx 2 homebridge homebridge 4096 Jul 3 20:02 persist
But when i try to start the homebridge deamon with sudo systemctl start homebridge
it not starts correctly.
journalctl -u homebridge shows:
...
[7/3/2019, 18:36:58] config.json (/var/lib/homebridge/config.json) not found.
...
How i can fix this problem ?
If you already added your homebridge/accessories in the Home App before migrating to systemd, then you will need to copy the files from your ~/.homebridge/persist to /var/lib/homebridge/persist. This is what fixed the issue of the Home app not responding to any accessories or the homebridge hub.
Verify that the path is accurate -- I had to add word "local" to the path in homebridge.service file.
ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
That ended up being my issue as well. I could manually start my second instance, but the service would not run. I had to change /usr/bin/homebridge to /usr/local/bin/homebridge and everything started working.
hello,
i followed the new instructions to install homebridge on raspberianOS, but i seem to fail to understand how to fix this error:
systemctl enable homebridge
=> update-rc.d: error: homebridge Default-Start contains no runlevels, aborting.
Any solutions?
Hello everyone! I want to run Homebridge in insecure mode.
Now from terminal i have to dohomebridge -I
.How can I implement it in the bootup script? Thanks :)
I got mine to work by editing the /usr/local/bin/homebridge and instead of using strict, changed to use insecure and it worked just fine
@kaaspad I too would like to know why the separate homebridge user is necessary, however from my experience it really is. I'd initially set up homebridge with the config.json in /home/pi/.homebridge. After some initial success, homebridge failed to run at boot time. I could still run it directly (just typing "homebridge"), but it failed to start when using systemctl. Looking at the errors, it appeared to be related to not being able to access the persist directory.
Changing to a separate homebridge user and putting the config.json in /var/homebridge (and having that directory owned by and writable by the homebridge user) fixed things.
Except of system services, systemd supports something that is called „user services” aswell.
The .service file (in the very same format as for system service, execpt the „user” property which should be omitted) are to be placed in /lib/systemd/user
Then, the service can be controlled (started, enabled, etc.) via sysctl by a regular user like pi.
Creating separate users have some sense when the service must be run with root privileges for some reason (like opening listen socket on port below 1024), amd usually after completing root actions the ownership of the running service is dropped to that (unprivileged) user.
In case of homebridge, there is absolutely NO need of running it with root privileges UNTIL you do not use plugins which require some elevated privileges. That is why running homebridge as a system service in most cases is not really required, in fact it creates some additional security risk.
I’d stick with user service (see first paragraph) or run homebridge via node’s pm2 manager which is more than comfortable.
Note for systemd users: Your start service needs to start the
NetworkManager-wait-online.service
before being able to wait after it is finished:[Unit] Description=Node.js HomeKit Server Wants=network-online.target After=syslog.target network-online.target
See https://unix.stackexchange.com/a/126146 for details.
This was the solution for me - thank you fuerst!
My Homebridge works manually fine.
I tried to implement the App in systemd like you did.
in /etc/systemd/system i wrote homebridge.service:
in /etc/default/homebridge this:
After:
systemctl daemon-reload
systemctl enable homebridge.service
systemctl start homebridge.service
systemctl status homebridge.service tells me that:
● homebridge.service - Node.js Homekit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: active (exited) since Do 2018-03-22 19:55:27 CET; 57min ago
Mär 22 19:55:30 DietPi sudo[21050]: pam_unix(sudo:session): session closed for user root
Mär 22 20:31:18 DietPi systemd[1]: [/etc/systemd/system/homebridge.service:5] Invalid section header '[Service] Type=simple'
Mär 22 20:31:41 DietPi systemd[1]: [/etc/systemd/system/homebridge.service:5] Invalid section header '[Service] Type=simple'
Mär 22 20:31:41 DietPi systemd[1]: [/etc/systemd/system/homebridge.service:5] Invalid section header '[Service] Type=simple'
Mär 22 20:33:08 DietPi systemd[1]: [/etc/systemd/system/homebridge.service:5] Invalid section header '[Service] Type=simple'
Mär 22 20:33:17 DietPi systemd[1]: [/etc/systemd/system/homebridge.service:5] Invalid section header '[Service] Type=simple'
Mär 22 20:33:17 DietPi systemd[1]: [/etc/systemd/system/homebridge.service:5] Invalid section header '[Service] Type=simple'
Mär 22 20:38:19 DietPi systemd[1]: Started Node.js Homekit Server.
Mär 22 20:40:19 DietPi systemd[1]: Started Node.js Homekit Server.
Mär 22 20:52:51 DietPi systemd[1]: Started Node.js Homekit Server.