Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
Owner
johannrichard commented Jan 7, 2016 edited

On newer Raspberry Pi and Debian systems (i.e. jessie based), managing of services with init.d/sysvinit is (transparently) replaced with systemd. If you wish to use systemd for running Homebridge on boot, you can follow these instructions. Familiarity with Linux concepts, user and rights management etc. are assumed.

As you can see, the service definition is much shorter than a comparable init.d script.

Download the two files and place homebridge under /etc/default and homebridge.service under /etc/systemd/system on your Raspberry Pi.

ATTENTION: Depending on how you installed nodejs (as package or tarball) and homebridge, you might have to change the line ExecStart in the file homebridge.service from /usr/local/bin/homebridge to /usr/bin/homebridge. The easiest way to find out which one to use is to issue the command which homebridge after you have installed homebridge on your system.

pi@pi:~ $ which homebridge
/usr/local/bin/homebridge

Configuration

In order to use the systemd service as is, the following folders and user have to exists:

  • A system user named homebridge. You can easily create this user with sudo useradd -M --system homebridge or choose a different name
  • A directory called /var/lib/homebridge, writable by the user created above, and a corresponding config.json file in that directory. Homebridge by default looks for its configuration in /home/<username>/.homebridge. This is unsuitable for services and the -U /var/lib/homebridge flag ensures the config is read from a different place.

Then Enable and run the service (first time) with the following commands:

systemctl daemon-reload
systemctl enable homebridge
systemctl start homebridge

You can check the status of the service by calling

systemctl status homebridge

On subsequent reboots, it should start automatically, if not, use the journalctl -u homebridge to check the error cause.

Notes

  • The service will restart after 10 seconds if it fails for any reason (or if you kill it for example with kill -s SIGSEGV <pid>)

Hi there, I was just wondering, what should be checked if I receive active (exited) instead of active (running)? I can't see what I've messed up ;_;

m0rph13 commented Jan 15, 2016

Although I did install homebridge globally, I found that on my PI it was installed on /usr/local/bin
Changing that got it up and running.
Thank you!

m0rph13 How did you do that?

I have managed to install systemd pn my raspberry pi however when I run the command "systemctl enable home bridge" I get "Failed to issue method call: Invalid argument"

Any ideas?

Thank you

@simonrb2000 If you called it with a space in there, that could have been the issue.

gretel commented Jan 28, 2016

great, thanks.

desvdp commented Jan 31, 2016

Great work, already switched to using systemd (I like the automatic restart feature !)
one thing: I'd suggest also waiting for the network to come up (otherwise platforms depending on an ip address might crash during boot)

After=syslog.target network-online.target

To me, everything seems to be working fine. If i manually start Homebridge, everything is fine and i can control my Nest perfectly.
$ homebridge

However, using the above mentioned method, i cannot seem to connect to Homebridge, nor the Nest. Calling
systemctl status homebridge

homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: active (running) since Wed 2016-02-03 20:34:30 UTC; 15min ago
Main PID: 320 (homebridge)
CGroup: /system.slice/homebridge.service
└─320 homebridge

Gives no specific errors. There are also no errors in the log file:

Feb 03 20:34:55 raspberrypi homebridge[320]: ---
Feb 03 20:34:55 raspberrypi homebridge[320]: Loaded config.json with 0 accessories and 1 platforms.
Feb 03 20:34:55 raspberrypi homebridge[320]: ---
Feb 03 20:34:55 raspberrypi homebridge[320]: Loading 1 platforms...
Feb 03 20:34:55 raspberrypi homebridge[320]: Initializing Nest platform...
Feb 03 20:34:55 raspberrypi homebridge[320]: Fetching Nest devices.
Feb 03 20:35:12 raspberrypi homebridge[320]: Current temperature for Family Room (Huiskamer) is: 21.5 C
Feb 03 20:35:12 raspberrypi homebridge[320]: Current humidity for Family Room (Huiskamer) is: 50%
Feb 03 20:35:12 raspberrypi homebridge[320]: Target temperature for Family Room (Huiskamer) is: 20.5 C
Feb 03 20:35:12 raspberrypi homebridge[320]: Target heating for Family Room (Huiskamer) is: Heating
Feb 03 20:35:12 raspberrypi homebridge[320]: Initializing platform accessory 'Family Room (Huiskamer)'...
Feb 03 20:35:12 raspberrypi homebridge[320]: Scan this code with your HomeKit App on your iOS device to pair with Ho
Feb 03 20:35:12 raspberrypi homebridge[320]:
Feb 03 20:35:12 raspberrypi homebridge[320]: ┌────────────┐
Feb 03 20:35:12 raspberrypi homebridge[320]: │ xx-xx-xx │
Feb 03 20:35:12 raspberrypi homebridge[320]: └────────────┘
Feb 03 20:35:12 raspberrypi homebridge[320]:
Feb 03 20:35:12 raspberrypi homebridge[320]: Homebridge is running on port 51826.
Feb 03 20:36:33 raspberrypi homebridge[320]: Current temperature for Family Room (Huiskamer) is: 21 C

Any ideas on how to find out what is going on?

-Edit
I think that i fixed the problem by changing the username for the homebridge, and re-adding it to Homekit (and deleting the previous). Everything seems to work fine now.

I can launch homebridge manually just fine and believe I followed these instructions but I keep getting this when I check the status:

● homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: activating (auto-restart) (Result: exit-code) since Thu 2016-02-04 20:46:13 AST; 2s ago
Process: 974 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=203/EXEC)
Main PID: 974 (code=exited, status=203/EXEC)

Any insight would be much appreciated. Thanks.

This all worked for me, but where are the log and err file with this configuration? /var/log/homebridge.* are not updating and journalctl says no journal files found (I didn't enable debug, just looking for the standard logs)

codenko commented Feb 14, 2016

I can launch homebridge manually just fine and believe I followed these instructions but I keep getting this when I check the status:

● homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: activating (auto-restart) (Result: exit-code) since Thu 2016-02-04 20:46:13 AST; 2s ago
Process: 974 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=203/EXEC)
Main PID: 974 (code=exited, status=203/EXEC)

Any insight would be much appreciated. Thanks.

Also having this issue.

Neblite commented Feb 15, 2016

@codenko & @kevince52

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

codenko commented Feb 15, 2016
pi@codenkopi:~ $ sudo systemctl status homebridge
● homebridge.service - Node.js HomeKit Server
   Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
   Active: active (running) since Mon 2016-02-15 14:20:19 PST; 8s ago
 Main PID: 1336 (homebridge)
   CGroup: /system.slice/homebridge.service
           └─1336 homebridge

Feb 15 14:20:27 codenkopi homebridge[1336]: [Nest] Current humidity for Wrangler is: 41
Feb 15 14:20:27 codenkopi homebridge[1336]: [Nest] Target heating for Wrangler is: 0
Feb 15 14:20:27 codenkopi homebridge[1336]: [Nest] Target temperature for Wrangler is: 29.326
Feb 15 14:20:27 codenkopi homebridge[1336]: [Nest] Initializing platform accessory 'Wrangler'...
Feb 15 14:20:27 codenkopi homebridge[1336]: Scan this code with your HomeKit App on your iOS device to pair with Homebridge:
Feb 15 14:20:27 codenkopi homebridge[1336]:
Feb 15 14:20:27 codenkopi homebridge[1336]:     ┌────────────┐
Feb 15 14:20:27 codenkopi homebridge[1336]:     │ ***-**-*** │
Feb 15 14:20:27 codenkopi homebridge[1336]:     └────────────┘
Feb 15 14:20:27 codenkopi homebridge[1336]:

pi@codenkopi:~ $ sudo 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 Mon 2016-02-15 14:20:28 PST; 2s ago
  Process: 1336 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
 Main PID: 1336 (code=exited, status=1/FAILURE)

Feb 15 14:20:28 codenkopi systemd[1]: Unit homebridge.service entered failed state.
pi@codenkopi:~ $

@Neblite. You were correct, the path was wrong. But even with the corrected path, it launches, only to fail a couple seconds later.

Hello guys,

I can also manually start Homebridge on my Pi 2, but I can't make it run on boot with this method.
I've put all the files at the right places and permissions are OK, but...

When typing: sudo systemctl enable homebridge

I get this:
Synchronizing state for homebridge.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d homebridge defaults
insserv: script homebridge is not an executable regular file, skipped!
Executing /usr/sbin/update-rc.d homebridge enable
update-rc.d: error: no runlevel symlinks to modify, aborting!

I'm guessing the error has to be here, but I can't understand it.

When checking the status I get this:
● homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: activating (auto-restart) (Result: exit-code) since mer. 2016-02-17 23:37:27 CET; 1s ago
Process: 1363 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
Main PID: 1363 (code=exited, status=1/FAILURE)

I've changed the path in homebridge.service file as explained by Neblite, but it doesn't help.

Thanx a lot in advance for your help !
Jerome

I had difficulty with same errors as listed above until taking two actions:

  1. Inserting 'local' into the file location as neblite stated;
  2. Making sure that /var/homebridge really was writable by the user 'homebridge' (set to 777).

Then repeating the steps:

systemctl daemon-reload
systemctl enable homebridge
systemctl start homebridge

codenko commented Feb 19, 2016

Ah, so getting more into this, when I try enabling homebridge, I get a whole bunch of errors.

sudo systemctl enable homebridge
Synchronizing state for homebridge.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d homebridge defaults
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for `Provides:' please add.
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for `Provides:' please add.

Neblite commented Feb 20, 2016

@codenko its likely that homebridge is already running in the background.
Verify whether or not this is true by running with the following command "systemctl status homebridge" or "journalctl -u homebridge"

You can also see if the process has already started with "ps aux | grep -i homebridge"

CBK482 commented Feb 22, 2016

For me, it started up, but everything seemed offling in Homekit app. Could not see the homebridge and accesories anymore.
I needed to remove and add again from the homekit db. I think it has something todo with the persistence directory not being copied from the original .homebridge folder. (only copied config.json to /var/homebridge)

sudo systemctl -l status homebridge adds also the tail of the log to the output

Same Problem here.

I´ve found a solution !!!

I copied the "persist" directory to the new directory /var/homebridge

sudo cp -r ~/.homebridge/persist /var/homebridge

geht

Works fine !
finally I can sometimes contribute ;-)

Sorry for the newbie question, but how do I make the user homebridge have write access to /var/homebridge

sudo chown -R homebridge:homebridge /var/homebridge
sudo chmod 777 -R /var/homebridge

I get this:

May 21 09:47:28 automator homebridge[30832]: [5/21/2016, 9:47:28 AM] Loading 1 platforms...
May 21 09:47:28 automator homebridge[30832]: [5/21/2016, 9:47:28 AM] [Vera] Initializing Vera platform...
May 21 09:47:28 automator homebridge[30832]: /usr/local/lib/node_modules/homebridge-vera/index.js:104
May 21 09:47:28 automator homebridge[30832]: if ( e.code != 'EEXIST' ) throw e;
May 21 09:47:28 automator homebridge[30832]: ^
May 21 09:47:28 automator homebridge[30832]: Error: ENOENT: no such file or directory, mkdir '/home/homebridge/.veralink'
May 21 09:47:28 automator homebridge[30832]: at Error (native)
May 21 09:47:28 automator homebridge[30832]: at Object.fs.mkdirSync (fs.js:794:18)
May 21 09:47:28 automator homebridge[30832]: at loadconfig (/usr/local/lib/node_modules/homebridge-vera/index.js:101:16)
May 21 09:47:28 automator homebridge[30832]: at Object.VeraLinkPlatform (/usr/local/lib/node_modules/homebridge-vera/index.js:23:23)
May 21 09:47:28 automator homebridge[30832]: at Server._loadPlatforms (/usr/local/lib/node_modules/homebridge/lib/server.js:273:32)
May 21 09:47:28 automator homebridge[30832]: at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:71:36)
May 21 09:47:28 automator homebridge[30832]: at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)
May 21 09:47:28 automator homebridge[30832]: at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
May 21 09:47:28 automator homebridge[30832]: at Module._compile (module.js:409:26)
May 21 09:47:28 automator homebridge[30832]: at Object.Module._extensions..js (module.js:416:10)
May 21 09:47:28 automator systemd[1]: homebridge.service: main process exited, code=exited, status=1/FAILURE
May 21 09:47:28 automator systemd[1]: Unit homebridge.service entered failed state.

so somehow home bridge still wants to write to the users home directory. Any clues on how to tell it to use /var/homebridge instead?

not sure if it is the right thing to do but I changed the home bridge home directory like this:

sudo usermod -m -d /var/homebridge homebridge

now its working

marl0n commented May 23, 2016 edited

Hi all, I'm a complete newbie in LINUX/RPi, but I once managed to get the Homebridge service working. I'm now reconfiguring my RPi and try to recreate this, but without luck. I've started out with a OS img with Domoticz and Homebridge pre-installed. After that I followed the steps as described here. I've also tried all the troubleshooting mentioned in the comments above, reinstalling, messing with privileges, moving files around.. barely knowing what I'm doing though ;)

What I'm getting when doing a systemctl status homebridge is sometimes a green light:

💚

● homebridge.service - Node.js HomeKit Server
   Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
   Active: active (running) since Mon 2016-05-23 14:16:42 UTC; 1s ago
 Main PID: 896 (homebridge)
   CGroup: /system.slice/homebridge.service
           └─896 homebridge

But that only lasts for a second or so. Mostly I get:

🔴

● homebridge.service - Node.js HomeKit Server
   Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
   Active: activating (auto-restart) (Result: exit-code) since Mon 2016-05-23 14:16:44 UTC; 79ms ago
  Process: 896 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
 Main PID: 896 (code=exited, status=1/FAILURE)

When starting Homebridge manually it did work. What am I doing wrong? I'm sometimes not sure in what user I have to do the commands: pi? homebridge? root?

Maybe someone knows the answer? :) Would be great!

SOLVED see next comment

marl0n commented May 23, 2016 edited

I think I found the problem. It was in the config.json file. Fixed an it now works sort of. Seems like Homebridge get stuck on something when starting after a reboot:

[eDomoticz] There was a problem connecting to Domoticz.

If I restart it by hand, it runs flawless:

sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge

So my 5 cents are that Homebridge is starting up while Domoticz is also busy startingup.. Homebridge is there faster and gets stuck. Is there a way to delay the startup of Homebridge?

SOLVED:
I used the great suggestion of desvdp:

I'd suggest also waiting for the network to come up (otherwise platforms depending on an ip address might crash during boot)
After=syslog.target network-online.target

Thx man! :)

jcbriones commented May 31, 2016 edited

Hey guys I need help. I am getting this error.

● homebridge.service - Node.js HomeKit Server
   Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2016-05-31 11:19:27 PHT; 8s ago
  Process: 2660 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
 Main PID: 2660 (code=exited, status=1/FAILURE)

May 31 11:19:27 sanchezhomekit systemd[1]: Unit homebridge.service entered failed state.

I compiled the steps I used in this quickstart. It's not nearly as detailed as the discussion here, but might help those having issues to see it all distilled down to a minimum configuration.

I see this in my error log

-- Logs begin at Sat 2016-06-11 20:53:42 PHT, end at Sat 2016-06-11 20:55:41 PHT. --
Jun 11 20:53:53 homekit systemd[1]: Starting Node.js HomeKit Server...
Jun 11 20:53:53 homekit systemd[1]: Started Node.js HomeKit Server.
Jun 11 20:53:55 homekit homebridge[619]: *** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
Jun 11 20:53:55 homekit node[619]: *** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
Jun 11 20:53:55 homekit node[619]: *** WARNING *** Please fix your application to use the native API of Avahi!
Jun 11 20:53:55 homekit node[619]: *** WARNING *** For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node
Jun 11 20:53:55 homekit node[619]: *** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partia
Jun 11 20:53:55 homekit node[619]: *** WARNING *** Please fix your application to use the native API of Avahi!
Jun 11 20:53:55 homekit node[619]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister
Jun 11 20:53:55 homekit homebridge[619]: *** WARNING *** Please fix your application to use the native API of Avahi!
Jun 11 20:53:55 homekit homebridge[619]: *** WARNING *** For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node
Jun 11 20:53:55 homekit homebridge[619]: *** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported
Jun 11 20:53:55 homekit homebridge[619]: *** WARNING *** Please fix your application to use the native API of Avahi!
Jun 11 20:53:55 homekit homebridge[619]: *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRe
Jun 11 20:53:56 homekit homebridge[619]: [Sat Jun 11 2016 20:53:56 GMT+0800 (PHT)] Loaded plugin: homebridge-people
Jun 11 20:53:56 homekit homebridge[619]: [Sat Jun 11 2016 20:53:56 GMT+0800 (PHT)] Registering accessory 'homebridge-people.people'
Jun 11 20:53:56 homekit homebridge[619]: [Sat Jun 11 2016 20:53:56 GMT+0800 (PHT)] ---
Jun 11 20:53:56 homekit homebridge[619]: wiringPiSetup: Unable to open /dev/gpiomem: Permission denied
Jun 11 20:53:56 homekit systemd[1]: homebridge.service: main process exited, code=exited, status=1/FAILURE
Jun 11 20:53:56 homekit systemd[1]: Unit homebridge.service entered failed state.
Jun 11 20:54:15 homekit systemd[1]: homebridge.service holdoff time over, scheduling restart.
Jun 11 20:54:15 homekit systemd[1]: Stopping Node.js HomeKit Server...

Thanks for this, completed all the steps however when try to start the service I get the following errors:

pi@raspberrypi ~ $ systemctl daemon-reload
bash: systemctl: command not found
pi@raspberrypi ~ $ systemctl enable homebridge
bash: systemctl: command not found
pi@raspberrypi ~ $ systemctl start homebridge
bash: systemctl: command not found
pi@raspberrypi ~ $

Thanks

Hi there
Still having the same issue : green / red light with systemctl status homebridge command...
When I lunch homebridge manually everything is fine... Can't figure out what I am doing wrong
Thanks for your help

Dracoy commented Jun 30, 2016

Same issue as @dreameruk - command not found, anyone know why?

kaaspad commented Jul 14, 2016 edited

Hi I was wondering why the need for another user (homebridge) and the creation of config under var? Since the setup is done mostly using a default user like "pi" why not just use the defaults? As well as the default location for the config?
I set up mine as follows and it works great - is there an issue with doing it like this?

pi@YYYY:~ $ more /etc/default/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 /home/pi/.homebridge

# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u home bridge
# DEBUG=*

and then the service looks like this:

[Unit]
Description=homebridge_service
After=basic.target
[Service]
Type=simple
User=pi
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-abort
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target

I'm not even sure that the above flag "Type"

@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.

jilsx commented Jul 29, 2016

I just solved my problem with the Homebridge service not starting... I changed the password to Home Assistant, but failed to update the config.json for Homebridge. Newbie error :(

Owner
johannrichard commented Aug 9, 2016 edited

@espresso1736 @kaaspad, technically, using the default user pi and keeping the configuration under /home/pi/.homebridge is fine and works, as you found out. However, it is considered best practice to run a service (any service) on a Linux system under its dedicated, own user account. Benefits are better security (credentials and other security elements like tokens are only accessible to this user and root), a clearer separation from things run by a user vs. things running when the system starts etc.

If you look at other service definitions on your Raspberry Pi, you will find that most if not all of them operate this way. The downside is that running homebridge for debugging purposes with your user account is getting more difficult.

I hope that helps.

Owner
johannrichard commented Aug 9, 2016 edited

@Dracoy @dreameruk essentially, this means that your Raspberry Pi is running services with sysvinit, the older and arguably more complicated way to create and run services, and that systemd is missing.

It could be that the version of your operating system is an older one. If I recall correctly (and as stated in the first comment), it's only newer Raspbian/Debian versions (I.e. jessie based) that use systemd for running services, whereas wheezy based Raspbian still use sysvinit.

Try

cat /etc/*-release

or

cat /proc/version

or

lsb_release -a

to find out which version of Debian/Raspbian you're running.

Owner
johannrichard commented Aug 9, 2016 edited

@jcbriones I guess the culprit is one of your plugins and/or missing rights. In your log, you find a line where wiringPi is complaining about missing access to /dev/gpiomem.

You would have to find out whether this particular device exists (assuming you run this on a Raspberry Pi or compatible board, it should) and if so, whether there are some user rights need to be set.

Since I'm not familiar with wiringPi and don't know what board and setup you have, I'm afraid you have to figure this out yourself.

Maybe this article from the author of wiringPi is a good starting point, assuming that you are somewhat familiar with Linux commands and concepts.

http://wiringpi.com/wiringpi-update-to-2-29/

Owner
johannrichard commented Aug 9, 2016 edited

Thanks for all the many comments, I have added some modifications to the script, namely using /usr/local/bin as path and adding a dependency for network-online.target to the service definition.

setje commented Aug 12, 2016

Hello,
I am running homebridge on a Raspberry Pi 2 with Debian jessie. Everything works fine, I can control my Homematic devices per iOS 10 Home app.
Then I decided to start homebridge automatically on boot. The homebridge is starting, but I don't see my devices (e.g. thermostats). When I type sudo systemctl stop homebridge followed by sudo systemctl start homebridge the devices are visible.

When is look for active processes by typing ps aux | grep -i homebridge I get the following results:

homebri+ 1519 3.2 4.2 137688 41992 ? Ssl 06:11 0:06 homebridge
pi 1561 0.0 0.1 4276 1896 pts/2 S+ 06:14 0:00 grep --color=auto -i homebridge

What am I doing wrong? Thank you!

@setje. I have a similar issue with openhab and homebridge. I also have a harmony which loads fine. Looking at the logs it seemed like the homebridge is coming online before openhab is online so the devices are not visible. When i do the stop and start the openhab is online by then and so it works. need help figuring out where to make the change and what exactly to type.

I did another image and installed homebridge using the systemd method. Homebridge service is running but it seems it started before openhab service could start

● homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: active (running) since Sat 2016-08-20 00:10:06 UTC; 7min ago
Main PID: 564 (homebridge)
CGroup: /system.slice/homebridge.service
└─564 homebridge

Aug 20 00:10:33 raspberrypi homebridge[564]: [8/20/2016, 12:10:33 AM] [openHAB] Platform - Connecting to http://192.168.100.18:8080/rest/sitemaps/MyHomebridge?type=json
Aug 20 00:10:33 raspberrypi homebridge[564]: [8/20/2016, 12:10:33 AM] [openHAB] Platform - There was a problem connecting to OpenHAB.
Aug 20 00:10:35 raspberrypi homebridge[564]: [8/20/2016, 12:10:35 AM] [Living Room Harmony Hub] Fetching Logitech Harmony activities...
Aug 20 00:10:36 raspberrypi homebridge[564]: [8/20/2016, 12:10:36 AM] [Living Room Harmony Hub] Found activities:
Aug 20 00:10:36 raspberrypi homebridge[564]: Night Night
Aug 20 00:10:36 raspberrypi homebridge[564]: All off
Aug 20 00:10:36 raspberrypi homebridge[564]: CableTV
Aug 20 00:10:36 raspberrypi homebridge[564]: Apple TV
Aug 20 00:10:36 raspberrypi homebridge[564]: PowerOff
Aug 20 00:10:36 raspberrypi homebridge[564]: Friday Night

pi@raspberrypi:~ $ journalctl -u homebridge
No journal files were found.

pi@raspberrypi:~ $ ls -l /var/homebridge
total 12
drwxr-xr-x 2 homebridge homebridge 4096 Aug 19 23:41 accessories
-rwxrwxrwx 1 homebridge homebridge 444 Aug 19 23:16 config.json
drwxr-xr-x 2 homebridge homebridge 4096 Aug 19 23:41 persist

any help would be very much appreciated. it works if i restart using systemctl restart homebridge after a few mins of booting

pi@raspberrypi:~ $ sudo systemctl restart homebridge
pi@raspberrypi:~ $ sudo systemctl status homebridge -l
● homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
Active: active (running) since Sat 2016-08-20 00:23:49 UTC; 27s ago
Main PID: 1665 (homebridge)
CGroup: /system.slice/homebridge.service
└─1665 homebridge

Aug 20 00:23:58 raspberrypi homebridge[1665]: [8/20/2016, 12:23:58 AM] [openHAB] OpenHAB WS - new connection for Living Room Sofa
Aug 20 00:23:58 raspberrypi homebridge[1665]: [8/20/2016, 12:23:58 AM] [openHAB] OpenHAB WS - new connection for Toilet
Aug 20 00:23:58 raspberrypi homebridge[1665]: [8/20/2016, 12:23:58 AM] [Living Room Harmony Hub] Fetching Logitech Harmony activities...
Aug 20 00:24:00 raspberrypi homebridge[1665]: [8/20/2016, 12:24:00 AM] [Living Room Harmony Hub] Found activities:
Aug 20 00:24:00 raspberrypi homebridge[1665]: Night Night
Aug 20 00:24:00 raspberrypi homebridge[1665]: All off
Aug 20 00:24:00 raspberrypi homebridge[1665]: CableTV
Aug 20 00:24:00 raspberrypi homebridge[1665]: Apple TV
Aug 20 00:24:00 raspberrypi homebridge[1665]: PowerOff
Aug 20 00:24:00 raspberrypi homebridge[1665]: Friday Night

Same problem.

Only works if i restart after a few minutes.

Any solution??

If your homebridge contains a accessory that uses gpio, your homebridge will likely not work with a user different than root or pi because the homebridge user doesn't have permission to access gpio.

I found two solutions that worked for me, and I only tested with Raspbian Jessie. You can either add homebridge user to gpio group

usermod -a -G gpio homebridge

Or you can remove User=homebridge in homebridge.service

DrSurround commented Sep 21, 2016 edited

I feel like i'm really close. When running manually it picks up my config.json file but when running as a service it does not. I see it run but not find any of my devices as it does manually. I've created the user, checked permissions, etc. I just can't figure out how to tell it to find config.json

homebridge.service - Node.js HomeKit Server
   Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
   Active: active (running) since Tue 2016-09-20 20:24:29 PDT; 16min ago
 Main PID: 7749 (homebridge)
   CGroup: /system.slice/homebridge.service
           └─7749 homebridge

Sep 20 20:24:32 raspberrypi homebridge[7749]: [9/20/2016, 8:24:32 PM] Registering platform 'homebridge-smartthings.SmartThings'
Sep 20 20:24:32 raspberrypi homebridge[7749]: [9/20/2016, 8:24:32 PM] ---
Sep 20 20:24:32 raspberrypi homebridge[7749]: Scan this code with your HomeKit App on your iOS device to pair with Homebridge:
Sep 20 20:24:32 raspberrypi homebridge[7749]:
Sep 20 20:24:32 raspberrypi homebridge[7749]:     ┌────────────┐
Sep 20 20:24:32 raspberrypi homebridge[7749]:     │ ***-**-*** │
Sep 20 20:24:32 raspberrypi homebridge[7749]:     └────────────┘
Sep 20 20:24:32 raspberrypi homebridge[7749]:
Sep 20 20:24:32 raspberrypi homebridge[7749]: [9/20/2016, 8:24:32 PM] Homebridge is running on port 51826.
Sep 20 20:40:42 raspberrypi systemd[1]: Started Node.js HomeKit Server.

Any help would be appreciated

SonicRevolutions commented Sep 24, 2016 edited

I get this error when using systemd:

Sep 24 23:35:28 raspi systemd[1]: Starting Node.js HomeKit Server...
Sep 24 23:35:28 raspi systemd[1]: Started Node.js HomeKit Server.
Sep 24 23:35:29 raspi homebridge[2206]: module.js:457
Sep 24 23:35:29 raspi homebridge[2206]: throw err;
Sep 24 23:35:29 raspi homebridge[2206]: ^
Sep 24 23:35:29 raspi homebridge[2206]: Error: Cannot find module 'hap-nodejs'
Sep 24 23:35:29 raspi homebridge[2206]: at Function.Module._resolveFilename (module.js:455:15)
Sep 24 23:35:29 raspi homebridge[2206]: at Function.Module._load (module.js:403:25)
Sep 24 23:35:29 raspi homebridge[2206]: at Module.require (module.js:483:17)
Sep 24 23:35:29 raspi homebridge[2206]: at require (internal/module.js:20:19)
Sep 24 23:35:29 raspi homebridge[2206]: at Object. (/usr/local/lib/node_modules/homebridge/lib/cli.js:2:11)
Sep 24 23:35:29 raspi homebridge[2206]: at Module._compile (module.js:556:32)
Sep 24 23:35:29 raspi homebridge[2206]: at Object.Module._extensions..js (module.js:565:10)
Sep 24 23:35:29 raspi homebridge[2206]: at Module.load (module.js:473:32)
Sep 24 23:35:29 raspi homebridge[2206]: at tryModuleLoad (module.js:432:12)
Sep 24 23:35:29 raspi homebridge[2206]: at Function.Module._load (module.js:424:3)
Sep 24 23:35:29 raspi systemd[1]: homebridge.service: main process exited, code=exited, status=1/FAILURE
Sep 24 23:35:29 raspi systemd[1]: Unit homebridge.service entered failed state.
Sep 24 23:35:35 raspi systemd[1]: Stopping Node.js HomeKit Server...
Sep 24 23:35:35 raspi systemd[1]: Stopped Node.js HomeKit Server.

Starting it from the command line works perfectly:

homebridge@raspi:~$ homebridge -U /var/homebridge
*** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs
*** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister
[9/24/2016, 11:18:12 PM] Loaded plugin: homebridge-homewizard
[9/24/2016, 11:18:12 PM] Registering platform 'homebridge-homewizard.HomeWizard'
[9/24/2016, 11:18:12 PM] ---
[9/24/2016, 11:18:13 PM] Loaded plugin: homebridge-sonos
[9/24/2016, 11:18:13 PM] Registering accessory 'homebridge-sonos.Sonos'
[9/24/2016, 11:18:13 PM] ---
[9/24/2016, 11:18:15 PM] Loaded plugin: homebridge-toon
[9/24/2016, 11:18:15 PM] Registering accessory 'homebridge-toon.Toon'
[9/24/2016, 11:18:15 PM] ---
[9/24/2016, 11:18:15 PM] Loaded config.json with 3 accessories and 1 platforms.
[9/24/2016, 11:18:15 PM] ---
[9/24/2016, 11:18:15 PM] Loading 1 platforms...
[9/24/2016, 11:18:15 PM] Initializing HomeWizard platform...
[9/24/2016, 11:18:15 PM] Loading 3 accessories...

Any ideas?

@sonicrevolutions it looks like the service isn't finding the hap-nodejs module.

Maybe the service runs as a different user, and the module isn't installed globally? If not check environment variables that might be set in your shell but may not be seen by the service.

Did some more debugging and found out it tries to create this folder /usr/lib/node_modules/homebridge/node_modules/node-persist/storage and got a permission denied. Could be a permission goof on my part so created the folder and did a chown homebridge. Now it's working properly.

Hi!
I followed all the steps, but I kept getting the following error when checking sudo systemctl status homebridge:
ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
I coped the persist folder to /var/homebridge

then I went to /usr/local/bin/ and I realized that I cant see anything related to homebridge there..
so I changed the ExecStart to ExecStart=/usr/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS

and then the service started!

Next step was to check the journaltl for any clues about the error and from the logs I found that homebridge complained about:
Error: EACCES: permission denied, open '/var/homebridge/persist/AccessoryInfo.CC223DE3XXXX.jsonI did a chmod 777 on all the files in the persist folder and the service now works!!

Please tell me if this is only a coincidence... or if I did something in the meantime that made the app work!
I am running Raspbian on a Pi2

sebask commented Sep 28, 2016

@jorgibravo Changing the ExecStart to ExecStart=/usr/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS worked here too. Thanks!

nzbadge commented Oct 4, 2016

@jorgibravo - your steps fixed my issue also. Thanks heaps

frodeaux commented Oct 7, 2016

When enabling this it worked fine. I had no issues. Then I installed an accessory on the pi that requires use of wiring pi that needs root access. The server fails to start. I quit the service and ran it manually, the error I got a "did you run this a sudo" before home bridge exited. So I ran # sudo homebridge -U /var/homebridge. and it started just fine. It will not start via this method however. Is there any way to fix that ?

timleland commented Oct 13, 2016 edited

This gist and comments help me to get Homebridge to start on boot on my Raspberry Pi. I did run into some issues and detailed my instructions in a blog post: https://timleland.com/setup-homebridge-to-start-on-bootup/ Hope this helps others.

Cloudore commented Oct 14, 2016 edited

Complete unix and command line first timer here, while following all these steps, I get home bridge to start at boot, however I have no idea how to do the following step:

Homebridge by default looks for its configuration in /home//.homebridge. This is unsuitable for services and the -U /var/homebridge flag ensures the config is read from a different place.

I tried /home/pi/.homebridge -U /var/homebridge but it kept telling me it was a directory, could anyone help me on the proper syntax for this step?

Also, If I let homebridge boot this way, then ssh into the pi and type homebridge in terminal, it will start up and show me the code just fine but below it will be an error message: dns conflict, but if I sudo kill the process and start homebridge again it runs just fine.

Any help would be much appreciated!

Kerat5 commented Oct 20, 2016 edited

Thank you Cloudore, the help with the permissions was exactly one of the problems I had. I was able to resolve creating the system account and changing the permissions on the associated directories and files on my own. otherwise johannrichard's guide is perfect.

jcleek commented Dec 6, 2016

If you were sent here from https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi and you followed those instructions, you probably removed "local" from the path in the "Install Homebridge and dependencies" section and are having issues getting the service to run automatically, BUT when you run homebridge manually it works perfectly:

The issue is in the file homebridge.service above. Notice line 9:

ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS

That is incorrect because when you followed the instructions to install node.js using the apt-get method. If you did that, simply remove the local from the path to look like:

ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS

Save it and re-do these commands to set up the service again:

sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge

im getting this
homebridge.service - Node.js HomeKit Server
Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2016-12-14 19:00:59 CST; 5s ago
Process: 1328 ExecStart=/usr/local/node/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS
Main PID: 1328 (code=exited, status=126)

Dec 14 19:00:59 ubuntu systemd[1]: homebridge.service: Unit entered failed state.
Dec 14 19:00:59 ubuntu systemd[1]: homebridge.service: Failed with result 'exit-code'.

This is what I'm currently getting:

pi@raspberrypi:~ $ 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 Sun 2017-01-01 18:03:53 MST; 7s ago Process: 3349 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=203/EXEC) Main PID: 3349 (code=exited, status=203/EXEC)

Any ideas?

I tried what @jorgibravo recommended and changed the ExecStart to ExecStart=/usr/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS

and actually had it successfully start. (nothing actually activated in the homekit app, but the status showed success at least)

pi@raspberrypi:/etc/systemd/system $ systemctl status homebridge ● homebridge.service - Node.js HomeKit Server Loaded: loaded (/etc/systemd/system/homebridge.service; enabled) Active: active (running) since Sun 2017-01-01 18:28:24 MST; 6s ago Main PID: 9719 (homebridge) CGroup: /system.slice/homebridge.service └─9719 homebridge

but then after a while I checked the status again and got:
pi@raspberrypi:/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 Sun 2017-01-01 18:29:24 MST; 3s ago Process: 10016 ExecStart=/usr/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE) Main PID: 10016 (code=exited, status=1/FAILURE)

jsmith79 commented Jan 2, 2017

@quicksilverusu did you end up getting yours working?

@jsmith79 nope. still stuck. :(

actually yes it started working. for some reason it didn't take my chmod commands to give write access to 'homebridge'.

dony71 commented Jan 4, 2017 edited

Where is log file?
Can't find any /var/log/homebridge.log
Also, is it possible to have pid file?

Newbie that can't figure out permissions. When I try to transfer the above files from downloads to the directories outlined it tells me I do not have permission. I googled how to change permissions, yet it's not working. Can someone please walk me through this task. Thank you.

Owner

@shawnlowrey You have to sudo to get the necessary permissions. For example, if you want to copy the file from your user home (i.e. ~/homebridge.service), you can issue the following command:

sudo cp ~/homebridge.service /etc/systemd/system

Then you should find the file in the /etc/systemd/system and can move on from there.

@quicksilverusu @jsmith79 I had the same issue. Turned out I had the config.json and persist folder placed into /var/homebridge because I copied some commands from the comments, and not var/lib/homebridge where they should be. So I copied both things to the new folder, did the chmod 777 on all the files in the folder and now it works.

And for ExecStart is used the result of the command which homebridge, which gave me /usr/bin/homebridge. Even though my homebridge files are also located at /usr/lib/node_modules/homebridge/bin/homebridge.

hi, got this working, thx so far
just a question:

A directory called /var/lib/homebridge, writable by the user created above, and a corresponding config.json file in that directory. Homebridge by default looks for its configuration in /home//.homebridge. This is unsuitable for services and the -U /var/lib/homebridge flag ensures the config is read from a different place.

do I have to adapt the config.json in /home//.homebridge (was my standard) or
must I adapt the file in /var/lib/homebridge for the future?

thx neo

Hi People,

I am gettings this error any clue?

pi@raspberrypi:~ $ sudo systemctl enable homebridge
Synchronizing state for homebridge.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d homebridge defaults
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for Provides:' please add. insserv: Script homebridge is broken: incomplete LSB comment. insserv: missing valid name forProvides:' please add.
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for Provides:' please add. insserv: Script homebridge is broken: incomplete LSB comment. insserv: missing valid name forProvides:' please add.
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for Provides:' please add. insserv: Script homebridge is broken: incomplete LSB comment. insserv: missing valid name forProvides:' please add.
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for Provides:' please add. insserv: script homebridge is not an executable regular file, skipped! Executing /usr/sbin/update-rc.d homebridge enable insserv: Script homebridge is broken: incomplete LSB comment. insserv: missing valid name forProvides:' please add.
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for Provides:' please add. insserv: Script homebridge is broken: incomplete LSB comment. insserv: missing valid name forProvides:' please add.
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for Provides:' please add. insserv: Script homebridge is broken: incomplete LSB comment. insserv: missing valid name forProvides:' please add.
insserv: Script homebridge is broken: incomplete LSB comment.
insserv: missing valid name for Provides:' please add. insserv: Script homebridge is broken: incomplete LSB comment. insserv: missing valid name forProvides:' please add.
insserv: script homebridge is not an executable regular file, skipped!

Got mine working, but the only issue I have is I can't get it to work when I am away from home the home apps says connection failed. I have reset my Apple TV and stuff but no luck. Any ideas?

MatsA commented Jan 16, 2017

A stripped down version is posted here
http://pysselilivet.blogspot.com/2017/01/homebridge-autostart-with-systemd.html
and yes I know, it is not best practice…..
But if You just run Homebridge on the RPI maybe You could be forgiven ?

Here's a weird one for you...

I can't even get the documents moved into etc/default and etc/systemd/system. I'm getting an error that says "homebridge.service: Error moving file: Permssion denied"

What do I do? I tried changing the permissions of the folder to allow all users to add files, but it wouldn't let me do that either. Any help here would be appreciated.

Hi

I wanted to find out regarding the config.json file. If I wanted to make any changes to my config.json file which one shall I use inorder for homebridge to working correctly and on boot?

Thanks.

Thanks for this great tutorial, I also ran into the same problem as most of you: when manually starting homebridge, everything works fine, but with systemd boot, the homebridge service starts but the plugin returns no response . After trying many of the solutions from the comments, I think @stevenguh 's comment solved my problem: I have an bme280 sensors connected to the gpio, so after removing the 'User=homebridge' in homebridge.service as suggested, now the systemd service finally works! Thank you all for the help!

kevinwlau commented Apr 2, 2017 edited

I also had the problem many others had where the service would keep shutting down and auto-restarting, only to run for 1-2 seconds before restarting again. Even though I do not have anything using the gpio pins, removing the User=homebridge worked for me.

Hello everyone! I want to run Homebridge in insecure mode.
Now from terminal i have to do homebridge -I.

How can I implement it in the bootup script? Thanks :)

ddetton commented Apr 23, 2017

Homebridge was running fine if I just launched it directly from the command line but when I ran it as a service everything appeared to be running OK but none of my devices would respond in the Home app. All that I had to do to fix it was to delete the homebridge user, re-add the homebridge user then reset the file permissions for /var/lib/homebridge using the following command:

sudo chmod 777 /var/lib/homebridge -R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment