New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto start with OS X #316

Closed
dborup opened this Issue Oct 24, 2015 · 68 comments

Comments

Projects
None yet
@dborup

dborup commented Oct 24, 2015

Hi guys.

How do I make Homebridge start with OS X?

@maddox

This comment has been minimized.

Show comment
Hide comment
@maddox

maddox Oct 24, 2015

Collaborator

I started something here. It works fine for OS X, but I was having troubles with Linux.

Collaborator

maddox commented Oct 24, 2015

I started something here. It works fine for OS X, but I was having troubles with Linux.

@cflurin

This comment has been minimized.

Show comment
Hide comment
@cflurin

cflurin Oct 24, 2015

Contributor

I used pm2 for RPi Jessie, it should work with OS X too. Take a look here

Contributor

cflurin commented Oct 24, 2015

I used pm2 for RPi Jessie, it should work with OS X too. Take a look here

@fitzage

This comment has been minimized.

Show comment
Hide comment
@fitzage

fitzage Oct 24, 2015

pm2 appears to not work with OS X, but this seems to tell you how to pull it off using launchd. Not homebridge specific, but maybe it will work. https://gist.github.com/jczaplew/bf3a33c5a82a2d93bba4

[Or I should say the part of pm2 that generates the startup script doesn't work in OS X.]

fitzage commented Oct 24, 2015

pm2 appears to not work with OS X, but this seems to tell you how to pull it off using launchd. Not homebridge specific, but maybe it will work. https://gist.github.com/jczaplew/bf3a33c5a82a2d93bba4

[Or I should say the part of pm2 that generates the startup script doesn't work in OS X.]

@maddox

This comment has been minimized.

Show comment
Hide comment
@maddox

maddox Oct 24, 2015

Collaborator

This is exactly what the referenced branch does. I'd love for someone else to try it as well.

On Oct 24, 2015, at 10:37 AM, Matthew Fitzsimmons notifications@github.com wrote:

pm2 appears to not work with OS X, but this seems to tell you how to pull it off using launchd. Not homebridge specific, but maybe it will work. https://gist.github.com/jczaplew/bf3a33c5a82a2d93bba4


Reply to this email directly or view it on GitHub.

Collaborator

maddox commented Oct 24, 2015

This is exactly what the referenced branch does. I'd love for someone else to try it as well.

On Oct 24, 2015, at 10:37 AM, Matthew Fitzsimmons notifications@github.com wrote:

pm2 appears to not work with OS X, but this seems to tell you how to pull it off using launchd. Not homebridge specific, but maybe it will work. https://gist.github.com/jczaplew/bf3a33c5a82a2d93bba4


Reply to this email directly or view it on GitHub.

@fitzage

This comment has been minimized.

Show comment
Hide comment
@fitzage

fitzage Oct 24, 2015

I'll give it a shot when I get the chance. It looked too convoluted at first glance.

On Oct 24, 2015, at 7:45 AM, Jon Maddox notifications@github.com wrote:

This is exactly what the referenced branch does. I'd love for someone else to try it as well.

On Oct 24, 2015, at 10:37 AM, Matthew Fitzsimmons notifications@github.com wrote:

pm2 appears to not work with OS X, but this seems to tell you how to pull it off using launchd. Not homebridge specific, but maybe it will work. https://gist.github.com/jczaplew/bf3a33c5a82a2d93bba4


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub.

fitzage commented Oct 24, 2015

I'll give it a shot when I get the chance. It looked too convoluted at first glance.

On Oct 24, 2015, at 7:45 AM, Jon Maddox notifications@github.com wrote:

This is exactly what the referenced branch does. I'd love for someone else to try it as well.

On Oct 24, 2015, at 10:37 AM, Matthew Fitzsimmons notifications@github.com wrote:

pm2 appears to not work with OS X, but this seems to tell you how to pull it off using launchd. Not homebridge specific, but maybe it will work. https://gist.github.com/jczaplew/bf3a33c5a82a2d93bba4


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub.

@maddox

This comment has been minimized.

Show comment
Hide comment
@maddox

maddox Oct 24, 2015

Collaborator

It looked too convoluted at first glance

Its actually just a matter of calling 2 things. This pull actually wraps stuff up to make it simpler. Check out the README on the branch.

All you should have to do is run script/bootstrap and then script/install, and it will be running in the background and will launch on boot.

Collaborator

maddox commented Oct 24, 2015

It looked too convoluted at first glance

Its actually just a matter of calling 2 things. This pull actually wraps stuff up to make it simpler. Check out the README on the branch.

All you should have to do is run script/bootstrap and then script/install, and it will be running in the background and will launch on boot.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 1, 2015

I can't figure out any of the above methods :/ - not sure why there isn't a simple step by step in the wiki for keeping this alive in the background for OS X users.

Changing my branch to Maddox branch just enters homebridge into a world of problems. All I want to do is create a simple launchd script that works. The above gist does that really helpful thing of just skipping over all the important bits (copy the plist below and enter your information...for example, right, what information??)

realdannys commented Dec 1, 2015

I can't figure out any of the above methods :/ - not sure why there isn't a simple step by step in the wiki for keeping this alive in the background for OS X users.

Changing my branch to Maddox branch just enters homebridge into a world of problems. All I want to do is create a simple launchd script that works. The above gist does that really helpful thing of just skipping over all the important bits (copy the plist below and enter your information...for example, right, what information??)

@fitzage

This comment has been minimized.

Show comment
Hide comment
@fitzage

fitzage Dec 1, 2015

I created a launchd script with the new style globally nom installed version. I created it using Lingon X, which makes creating the launchd scripts much easier. I can give you the actual command later.

But there's a problem: half the reason for doing it this way is to keep it running if it crashes, but it doesn't seem to be working.

fitzage commented Dec 1, 2015

I created a launchd script with the new style globally nom installed version. I created it using Lingon X, which makes creating the launchd scripts much easier. I can give you the actual command later.

But there's a problem: half the reason for doing it this way is to keep it running if it crashes, but it doesn't seem to be working.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 1, 2015

Ah, thats exactly why I wanted to run it too - to restart after a crash, Homebridge crashes on a regular basis for me (at least a few times a day) and I need it to auto restart.

I finally figured out how to get forever to start it from the command line, but the only advantage to that is being able to close the terminal window, its still not going to restart when it crashes or start at boot.

realdannys commented Dec 1, 2015

Ah, thats exactly why I wanted to run it too - to restart after a crash, Homebridge crashes on a regular basis for me (at least a few times a day) and I need it to auto restart.

I finally figured out how to get forever to start it from the command line, but the only advantage to that is being able to close the terminal window, its still not going to restart when it crashes or start at boot.

@maddox

This comment has been minimized.

Show comment
Hide comment
@maddox

maddox Dec 1, 2015

Collaborator

I can't figure out any of the above methods :/ - not sure why there isn't a simple step by step in the wiki for keeping this alive in the background for OS X users.

There actually is, but on this branch. This branch has yet to be merged, so the instructions are not on the README at the root of this repo yet.

Changing my branch to Maddox branch just enters homebridge into a world of problems. All I want to do is create a simple launchd script that works.

This branch is behind master right now. Homebridge has changed A LOT since this branch was spun up. It's distributed and launched completely differently. This branch needs to be updated to reflect that.

Collaborator

maddox commented Dec 1, 2015

I can't figure out any of the above methods :/ - not sure why there isn't a simple step by step in the wiki for keeping this alive in the background for OS X users.

There actually is, but on this branch. This branch has yet to be merged, so the instructions are not on the README at the root of this repo yet.

Changing my branch to Maddox branch just enters homebridge into a world of problems. All I want to do is create a simple launchd script that works.

This branch is behind master right now. Homebridge has changed A LOT since this branch was spun up. It's distributed and launched completely differently. This branch needs to be updated to reflect that.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 1, 2015

@maddox I think thats the problem - I WANT to use your work, but I can't really at the minute as I need it to be merged with master - and trying to rebase myself is a hell land I can't attempt.

Id be happy to try and just take your work with the launchd script and roll it out manually, but i'm having no luck even trying to copy it over, but then thats probably because of the way homebridge is launched now too.

Typing "homebridge" to launch is so simple, and yet seemingly so difficult to do in the background, on boot and automatically relaunching after ever crash.

realdannys commented Dec 1, 2015

@maddox I think thats the problem - I WANT to use your work, but I can't really at the minute as I need it to be merged with master - and trying to rebase myself is a hell land I can't attempt.

Id be happy to try and just take your work with the launchd script and roll it out manually, but i'm having no luck even trying to copy it over, but then thats probably because of the way homebridge is launched now too.

Typing "homebridge" to launch is so simple, and yet seemingly so difficult to do in the background, on boot and automatically relaunching after ever crash.

@maddox

This comment has been minimized.

Show comment
Hide comment
@maddox

maddox Dec 1, 2015

Collaborator

It isn't a matter of just getting the branches synced up. Homebridge is launched completely differently now. So the existing launchd script won't work.

Beyond that, Homebridge is distributed via NPM now. It's not suggested to clone down the repo. Because of that, users won't even have a repo to go to to run script/install. So everything has to be be rethought out.

Most likely, there will need to be a command option added to the homebridge command to make it install the launchd script and launch that way.

Collaborator

maddox commented Dec 1, 2015

It isn't a matter of just getting the branches synced up. Homebridge is launched completely differently now. So the existing launchd script won't work.

Beyond that, Homebridge is distributed via NPM now. It's not suggested to clone down the repo. Because of that, users won't even have a repo to go to to run script/install. So everything has to be be rethought out.

Most likely, there will need to be a command option added to the homebridge command to make it install the launchd script and launch that way.

@fitzage

This comment has been minimized.

Show comment
Hide comment
@fitzage

fitzage Dec 1, 2015

OK, so I think I found the solution to my issue.

There's a launchd config option for KeepAlive called SuccessfulExit. It appears that this means that it will only keep the process running if it WASN'T a successful exit.

The default in Lingon X had SuccessfulExit enabled, and I think when homebridge is crashing it appears to launchd as if homebridge is exiting normally, so it doesn't relaunch it. I've removed the SuccessfulExit option, and if homebridge works correctly for three days or so, I'll know it has worked.

Now for what I did. If you have Lingon, you can tell it to run something like /usr/local/bin/homebridge -U /.homebridge where -U tells it there's an alternate location for the config file, and in my case that folder is at /.homebridge because I hope it will run if I'm not logged in. That means I also set it to run as root.

Then in the When section, I chose 'at startup and when saving' as well as 'always', and in the Advanced section I have no boxes checked, and no fields filled out.

Now if you want to manually create the plist file in /Library/LaunchDaemons, here's the contents I have:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/usr/local/sbin</string>
    </dict>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>Label</key>
    <string>com.fitzage.homebridge</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/homebridge</string>
        <string>-U</string>
        <string>/.homebridge</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

fitzage commented Dec 1, 2015

OK, so I think I found the solution to my issue.

There's a launchd config option for KeepAlive called SuccessfulExit. It appears that this means that it will only keep the process running if it WASN'T a successful exit.

The default in Lingon X had SuccessfulExit enabled, and I think when homebridge is crashing it appears to launchd as if homebridge is exiting normally, so it doesn't relaunch it. I've removed the SuccessfulExit option, and if homebridge works correctly for three days or so, I'll know it has worked.

Now for what I did. If you have Lingon, you can tell it to run something like /usr/local/bin/homebridge -U /.homebridge where -U tells it there's an alternate location for the config file, and in my case that folder is at /.homebridge because I hope it will run if I'm not logged in. That means I also set it to run as root.

Then in the When section, I chose 'at startup and when saving' as well as 'always', and in the Advanced section I have no boxes checked, and no fields filled out.

Now if you want to manually create the plist file in /Library/LaunchDaemons, here's the contents I have:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/usr/local/sbin</string>
    </dict>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>Label</key>
    <string>com.fitzage.homebridge</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/homebridge</string>
        <string>-U</string>
        <string>/.homebridge</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 1, 2015

Awesome that worked for me (so far!) except I had to chnage /.homebridge to my home folder where it installed as standard.

Just have to see what happens when it crashes now. I used LaunchControl to add logging for it so I can see whats going on too. I wonder if perhaps using Forever might be a good idea too, just for the fact that you can do some monitoring if you need to - but then again, checking the logs is just as easy to see whats going on.

My homebridge crashes every few hours so if its still working tonight when I come to turn the TV off I know its working just fine. It also crashes if I unplug the Logictech Harmony hub thats added to it, so I guess thats another test, if it'll resume again.

realdannys commented Dec 1, 2015

Awesome that worked for me (so far!) except I had to chnage /.homebridge to my home folder where it installed as standard.

Just have to see what happens when it crashes now. I used LaunchControl to add logging for it so I can see whats going on too. I wonder if perhaps using Forever might be a good idea too, just for the fact that you can do some monitoring if you need to - but then again, checking the logs is just as easy to see whats going on.

My homebridge crashes every few hours so if its still working tonight when I come to turn the TV off I know its working just fine. It also crashes if I unplug the Logictech Harmony hub thats added to it, so I guess thats another test, if it'll resume again.

@fitzage

This comment has been minimized.

Show comment
Hide comment
@fitzage

fitzage Dec 1, 2015

Yeah, you can certainly put .homebridge in the default location or anywhere you want. Since homebridge is installed globally, I figured I'd go global with it. Root level probably isn't the best move, but… ¯_(ツ)_/¯

I was never using Harmony, so I disabled it. That resolved most of my crashes. It seems that if there's a connection issue with the harmony hub, the harmony module just crashes homebridge. Wink used to do this, too. Now wink seems to handle errors better.

I was just using the legacy plugins for harmony still, but there is a module on npm. Not sure if that resolves the error handling issue or not.

fitzage commented Dec 1, 2015

Yeah, you can certainly put .homebridge in the default location or anywhere you want. Since homebridge is installed globally, I figured I'd go global with it. Root level probably isn't the best move, but… ¯_(ツ)_/¯

I was never using Harmony, so I disabled it. That resolved most of my crashes. It seems that if there's a connection issue with the harmony hub, the harmony module just crashes homebridge. Wink used to do this, too. Now wink seems to handle errors better.

I was just using the legacy plugins for harmony still, but there is a module on npm. Not sure if that resolves the error handling issue or not.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 2, 2015

So far so good! Yeah even the new Logitech plugin updated just a couple of days ago still doesn't have error handling so it crashes Homebridge when it becomes disconnected (which happens A LOT when you're first setting everything up!)

There's that and one other unhandled exception in Homebridge that i've reported which keeps happening. So far this looks great though, only once in testing has Siri not been able to reach the devices but it worked just fine when I tried immediately again - something i've read someone has had a few times, even with official Homekit devices.

realdannys commented Dec 2, 2015

So far so good! Yeah even the new Logitech plugin updated just a couple of days ago still doesn't have error handling so it crashes Homebridge when it becomes disconnected (which happens A LOT when you're first setting everything up!)

There's that and one other unhandled exception in Homebridge that i've reported which keeps happening. So far this looks great though, only once in testing has Siri not been able to reach the devices but it worked just fine when I tried immediately again - something i've read someone has had a few times, even with official Homekit devices.

@fitzage

This comment has been minimized.

Show comment
Hide comment
@fitzage

fitzage Dec 2, 2015

Nice. I did have an issue last night which could have been HomeKit crashing or just not connecting to the wink api at that point, but then it worked later.

fitzage commented Dec 2, 2015

Nice. I did have an issue last night which could have been HomeKit crashing or just not connecting to the wink api at that point, but then it worked later.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 3, 2015

Another topic, but my next adventure is to see how well Homebridge integrates with SmartThings, the combo of the two would be the holy grail, but I see SmartThings plugin hasn't even been updated out of the legacy collection (which means its either perfect, or was too hard to implement properly!)

realdannys commented Dec 3, 2015

Another topic, but my next adventure is to see how well Homebridge integrates with SmartThings, the combo of the two would be the holy grail, but I see SmartThings plugin hasn't even been updated out of the legacy collection (which means its either perfect, or was too hard to implement properly!)

@humac

This comment has been minimized.

Show comment
Hide comment
@humac

humac Dec 3, 2015

I've dabbled with the SmartThings integration and right now it only supports switch devices. Dimming doesn't work, motion, temp, contact sensors and other common capabilities are yet to be exposed. Also I find it doesn't sync state between ST and HomeKit at all.

humac commented Dec 3, 2015

I've dabbled with the SmartThings integration and right now it only supports switch devices. Dimming doesn't work, motion, temp, contact sensors and other common capabilities are yet to be exposed. Also I find it doesn't sync state between ST and HomeKit at all.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 5, 2015

I don't mind it being just switched as I plan to do all triggers with just SmartThings and use HomeKit for Siri only. Which means really I can only ever imagine asking Siri to turn things off and on. Generally I'm buying stuff thats both Homekit and SmartThings compatible (like Philips Hue) and things that will integrate well with Homekit via Homebridge. Not syncing the states between the two could be a bit of a nightmare though if you're using Siri to turn off a SmartThings socket.

realdannys commented Dec 5, 2015

I don't mind it being just switched as I plan to do all triggers with just SmartThings and use HomeKit for Siri only. Which means really I can only ever imagine asking Siri to turn things off and on. Generally I'm buying stuff thats both Homekit and SmartThings compatible (like Philips Hue) and things that will integrate well with Homekit via Homebridge. Not syncing the states between the two could be a bit of a nightmare though if you're using Siri to turn off a SmartThings socket.

@maddox

This comment has been minimized.

Show comment
Hide comment
@maddox

maddox Dec 5, 2015

Collaborator

@realdannys @humac would you guys mind opening a new issue regarding the SmartThings stuff, that's a bit off topic for this pull request. Thanks!

Collaborator

maddox commented Dec 5, 2015

@realdannys @humac would you guys mind opening a new issue regarding the SmartThings stuff, that's a bit off topic for this pull request. Thanks!

@humac

This comment has been minimized.

Show comment
Hide comment
@humac

humac Dec 5, 2015

@maddox sure thing sorry. Back to the topic on hand. So I used the script above on my mac mini and it worked to auto start homebridge however it crashed over night and didn't recover. Then after I rebooted the server and all the devices comeback but were no longer in the rooms and scenes I set up. It was as if homebridge was removed from homekit then rejoined. @realdannys How did you setup the logs using launchcontrol.

humac commented Dec 5, 2015

@maddox sure thing sorry. Back to the topic on hand. So I used the script above on my mac mini and it worked to auto start homebridge however it crashed over night and didn't recover. Then after I rebooted the server and all the devices comeback but were no longer in the rooms and scenes I set up. It was as if homebridge was removed from homekit then rejoined. @realdannys How did you setup the logs using launchcontrol.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 6, 2015

@humac, sure just add

    <key>StandardErrorPath</key>
<string>~/Library/Logs/Homebridge/homebridge.err</string>
<key>StandardOutPath</key>
<string>~/Library/Logs/Homebridge/homebridge.out</string>

After the keep alive in the plist and before the closing

That'll put the logs into console as well. Though I had issues with ~ so you might want to put your full user path (or remove it and put it into global logs, whatever you want, doesn't matter really)

realdannys commented Dec 6, 2015

@humac, sure just add

    <key>StandardErrorPath</key>
<string>~/Library/Logs/Homebridge/homebridge.err</string>
<key>StandardOutPath</key>
<string>~/Library/Logs/Homebridge/homebridge.out</string>

After the keep alive in the plist and before the closing

That'll put the logs into console as well. Though I had issues with ~ so you might want to put your full user path (or remove it and put it into global logs, whatever you want, doesn't matter really)

@humac

This comment has been minimized.

Show comment
Hide comment
@humac

humac Dec 7, 2015

@realdannys thanks got logging working and now I know why it wasn't loading on boot. It seems my netatmo plugin doesn't error out but stops the app from loading completely. And if i go into launchcontrol and unload and load launchdaemon everything is fine. Is there any way I can delay the daemon from loading?

humac commented Dec 7, 2015

@realdannys thanks got logging working and now I know why it wasn't loading on boot. It seems my netatmo plugin doesn't error out but stops the app from loading completely. And if i go into launchcontrol and unload and load launchdaemon everything is fine. Is there any way I can delay the daemon from loading?

@davidnewhall

This comment has been minimized.

Show comment
Hide comment
@davidnewhall

davidnewhall Dec 9, 2015

If you use auto-login, this quick and dirty solution works:

Open Script Editor (I believe it's included with OS X, if not, install Xcode or dev tools). Paste this into a new window:

do shell script "killall -9 homebridge ; eval $(/usr/libexec/path_helper -s); /Users/administrator/node_modules/homebridge/bin/homebridge > /dev/null 2>&1 &"

Fix the path to point to your homebrew app. You may capture output by directing it to somewhere other than /dev/null. Still in Script Editor, click File->Save... and change File Format to Application. Give it a name and save it somewhere. Locate the file using Finder and drag it to your dock. Right-click it in the dock, select options and choose Open At Login.

It will now open every time you login (and boot if you have auto-login turned on). If you have crashing issues, this won't help much, sorry.

davidnewhall commented Dec 9, 2015

If you use auto-login, this quick and dirty solution works:

Open Script Editor (I believe it's included with OS X, if not, install Xcode or dev tools). Paste this into a new window:

do shell script "killall -9 homebridge ; eval $(/usr/libexec/path_helper -s); /Users/administrator/node_modules/homebridge/bin/homebridge > /dev/null 2>&1 &"

Fix the path to point to your homebrew app. You may capture output by directing it to somewhere other than /dev/null. Still in Script Editor, click File->Save... and change File Format to Application. Give it a name and save it somewhere. Locate the file using Finder and drag it to your dock. Right-click it in the dock, select options and choose Open At Login.

It will now open every time you login (and boot if you have auto-login turned on). If you have crashing issues, this won't help much, sorry.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 10, 2015

Well I thought it was working fine, but in actual fact it doesn't load at boot at all. If I load the launchagent manually, no problems - and it'll keep homebridge alive, but if I reboot it doesn't automatically load, instead I get this error message in console

10/12/2015 12:30:52.448 com.apple.xpc.launchd[1]: (org.node.homebridge[942]) Service could not  initialize: 14F1505: xpcproxy + 13421 [1402][AD0301C4-D364-31CE-8BA7-B5DBECE64D0A]: 0xd
10/12/2015 12:30:52.448 com.apple.xpc.launchd[1]: (org.node.homebridge) Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

Seems to be some kind of permissions issue, but I can't find of what.

My full plist is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList- 1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/usr/local/sbin</string>
</dict>
<key>KeepAlive</key>
<dict>
    <key>Crashed</key>
    <true/>
    <key>SuccessfulExit</key>
    <false/>
</dict>
<key>Label</key>
<string>org.node.homebridge</string>
<key>ProgramArguments</key>
<array>
    <string>/usr/local/bin/homebridge</string>
    <string>-U</string>
    <string>/Users/Mac-mini/.homebridge</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/Mac-mini/Library/Logs/Homebridge/org.homebridge.err.log</string>
<key>StandardOutPath</key>
<string>/Users/Mac-mini/Library/Logs/Homebridge/org.homebridge.out.log</string>
</dict>
</plist>

The log files are chown'ed by root and i've even made my homebridge directory that way for testing too, but no luck on boot. Any ideas?

EDIT: Ignore the above i've got it working by forging the launch as root idea and just launching it as my user from ~/library/launchagents instead - this means I don't need to change owner on logs, folders etc and will make updating from NPM a lot easier.

realdannys commented Dec 10, 2015

Well I thought it was working fine, but in actual fact it doesn't load at boot at all. If I load the launchagent manually, no problems - and it'll keep homebridge alive, but if I reboot it doesn't automatically load, instead I get this error message in console

10/12/2015 12:30:52.448 com.apple.xpc.launchd[1]: (org.node.homebridge[942]) Service could not  initialize: 14F1505: xpcproxy + 13421 [1402][AD0301C4-D364-31CE-8BA7-B5DBECE64D0A]: 0xd
10/12/2015 12:30:52.448 com.apple.xpc.launchd[1]: (org.node.homebridge) Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

Seems to be some kind of permissions issue, but I can't find of what.

My full plist is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList- 1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/usr/local/sbin</string>
</dict>
<key>KeepAlive</key>
<dict>
    <key>Crashed</key>
    <true/>
    <key>SuccessfulExit</key>
    <false/>
</dict>
<key>Label</key>
<string>org.node.homebridge</string>
<key>ProgramArguments</key>
<array>
    <string>/usr/local/bin/homebridge</string>
    <string>-U</string>
    <string>/Users/Mac-mini/.homebridge</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/Mac-mini/Library/Logs/Homebridge/org.homebridge.err.log</string>
<key>StandardOutPath</key>
<string>/Users/Mac-mini/Library/Logs/Homebridge/org.homebridge.out.log</string>
</dict>
</plist>

The log files are chown'ed by root and i've even made my homebridge directory that way for testing too, but no luck on boot. Any ideas?

EDIT: Ignore the above i've got it working by forging the launch as root idea and just launching it as my user from ~/library/launchagents instead - this means I don't need to change owner on logs, folders etc and will make updating from NPM a lot easier.

@jdwhite

This comment has been minimized.

Show comment
Hide comment
@jdwhite

jdwhite Dec 12, 2015

Using the above plist as a template I tweaked the paths and non-root user accordingly, but also got the same Service could not initialize: 14F1505: xpcproxy error. For me the cause was that my ~/Library/Logs/Homebridge folder was owned by root -- even though I loaded it as non-root. My guess is that since launchd runs as root it created the directories as root. I changed ownership to my non-root user and the message went away.

The other thing I had to do was add <string>/usr/local/bin/node</string> as the first element of the ProgramArguments array. I also didn't need the PATH environment section, but your mileage may vary.

jdwhite commented Dec 12, 2015

Using the above plist as a template I tweaked the paths and non-root user accordingly, but also got the same Service could not initialize: 14F1505: xpcproxy error. For me the cause was that my ~/Library/Logs/Homebridge folder was owned by root -- even though I loaded it as non-root. My guess is that since launchd runs as root it created the directories as root. I changed ownership to my non-root user and the message went away.

The other thing I had to do was add <string>/usr/local/bin/node</string> as the first element of the ProgramArguments array. I also didn't need the PATH environment section, but your mileage may vary.

@chrischernoff

This comment has been minimized.

Show comment
Hide comment
@chrischernoff

chrischernoff Dec 22, 2015

So this might be a totally inefficient or incorrect way to do this, but thought it might help.

I've been able to get homebridge to run via launchd on El Capitan using the following:

(Note my node is installed via homebrew at /usr/local/bin/node)

  • Create a launchd file for homebridge and put it here ~/Library/LaunchAgents/homebridge.plist
  • Open the file and paste this in. You may need to modify paths based on your node/homebridge install locations (find out where your node is why typing which node)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>homebridge</string>
  <key>ProgramArguments</key>
  <array>
       <!-- Modify these two lines to reflect your node location and homebridge install location -->
       <string>/usr/local/bin/node</string>
       <string>/usr/local/bin/homebridge</string>
  </array>
  <key>StandardErrorPath</key>
  <string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.err.log</string>
  <key>StandardOutPath</key>
  <string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.out.log</string>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
</dict>
</plist>
  • sudo chmod 0600 ~/Library/LaunchAgents/homebridge.plist
  • sudo chown root ~/Library/LaunchAgents/homebridge.plist
  • Note once you run these two commands, in order to edit the plist as your non-root user in the future you'll need to open it with sudo, e.g. sudo vim ~/Library/LaunchAgents/homebridge.plist
  • To start the daemon use launchctl load ~/Library/LaunchAgents/homebridge.plist
  • To stop the daemon use launchctl unload ~/Library/LaunchAgents/homebridge.plist

Restart and try to control something with Siri, should be good to go!

Edit: I've updated my example plist to include logging as mentioned by @realdannys. You can name the <string> and plist filename whatever you like, I just kept it simple and called it homebridge. I think technically you'd want org.homebridge.plist, but it doesn't seem to matter.

chrischernoff commented Dec 22, 2015

So this might be a totally inefficient or incorrect way to do this, but thought it might help.

I've been able to get homebridge to run via launchd on El Capitan using the following:

(Note my node is installed via homebrew at /usr/local/bin/node)

  • Create a launchd file for homebridge and put it here ~/Library/LaunchAgents/homebridge.plist
  • Open the file and paste this in. You may need to modify paths based on your node/homebridge install locations (find out where your node is why typing which node)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>homebridge</string>
  <key>ProgramArguments</key>
  <array>
       <!-- Modify these two lines to reflect your node location and homebridge install location -->
       <string>/usr/local/bin/node</string>
       <string>/usr/local/bin/homebridge</string>
  </array>
  <key>StandardErrorPath</key>
  <string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.err.log</string>
  <key>StandardOutPath</key>
  <string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.out.log</string>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
</dict>
</plist>
  • sudo chmod 0600 ~/Library/LaunchAgents/homebridge.plist
  • sudo chown root ~/Library/LaunchAgents/homebridge.plist
  • Note once you run these two commands, in order to edit the plist as your non-root user in the future you'll need to open it with sudo, e.g. sudo vim ~/Library/LaunchAgents/homebridge.plist
  • To start the daemon use launchctl load ~/Library/LaunchAgents/homebridge.plist
  • To stop the daemon use launchctl unload ~/Library/LaunchAgents/homebridge.plist

Restart and try to control something with Siri, should be good to go!

Edit: I've updated my example plist to include logging as mentioned by @realdannys. You can name the <string> and plist filename whatever you like, I just kept it simple and called it homebridge. I think technically you'd want org.homebridge.plist, but it doesn't seem to matter.

@IMNotMax

This comment has been minimized.

Show comment
Hide comment
@IMNotMax

IMNotMax Dec 23, 2015

Hi all.
@chrischernoff I'm working on a similar inefficient or incorrect way on OS X =)
Maybe you can help : https://github.com/IMNotMax/homebridge-daemon
I have an issue, my PLIST is loaded but the ProgramArguments are not executed...

IMNotMax commented Dec 23, 2015

Hi all.
@chrischernoff I'm working on a similar inefficient or incorrect way on OS X =)
Maybe you can help : https://github.com/IMNotMax/homebridge-daemon
I have an issue, my PLIST is loaded but the ProgramArguments are not executed...

@IMNotMax

This comment has been minimized.

Show comment
Hide comment
@IMNotMax

IMNotMax Dec 23, 2015

EDIT: OK, DON'T USE THIS WAY BELOW :)

And for a user-friendly easy solution on OS X:
On terminal:
1/ First install Forever: `$ sudo npm install -g forever`

2/ then:
`$ VIM ~/homebridge-forever.bash`
*(for beginners: hit the i to go to insert mode)*
Paste: `/usr/local/bin/forever start /usr/local/bin/homebridge` 
*(for beginners: hit esc key and type `:wx` to write and exit VIM)*
3/ Type:
`$ chmod a+x ~/homebridge-forever.bash` to make this script executable

4/ Now:
Go to **Preferences** > **Users and Group** > ***Choose your user*** > Go to the panel **"On Start"** or **"At boot"** (I have a french OS X, I don't know the good translation)
Click on the **+** and add the script you previously create (in YOUR_USER_DIRECTORY)


With this "solution" you will have the Homebridge running Forever (even if it breaks, forever will restart it) without any terminal windows.
SO USE THIS TIP ONLY AFTER THE INITIAL CONFIGURATION (with a manual launch to see the startup messages) 

IMNotMax commented Dec 23, 2015

EDIT: OK, DON'T USE THIS WAY BELOW :)

And for a user-friendly easy solution on OS X:
On terminal:
1/ First install Forever: `$ sudo npm install -g forever`

2/ then:
`$ VIM ~/homebridge-forever.bash`
*(for beginners: hit the i to go to insert mode)*
Paste: `/usr/local/bin/forever start /usr/local/bin/homebridge` 
*(for beginners: hit esc key and type `:wx` to write and exit VIM)*
3/ Type:
`$ chmod a+x ~/homebridge-forever.bash` to make this script executable

4/ Now:
Go to **Preferences** > **Users and Group** > ***Choose your user*** > Go to the panel **"On Start"** or **"At boot"** (I have a french OS X, I don't know the good translation)
Click on the **+** and add the script you previously create (in YOUR_USER_DIRECTORY)


With this "solution" you will have the Homebridge running Forever (even if it breaks, forever will restart it) without any terminal windows.
SO USE THIS TIP ONLY AFTER THE INITIAL CONFIGURATION (with a manual launch to see the startup messages) 
@chrischernoff

This comment has been minimized.

Show comment
Hide comment
@chrischernoff

chrischernoff Dec 24, 2015

Strange. This is after a fresh restart? And your homebridge can be normally invoked from the terminal (e.g. just running homebridge) and it runs fine?

chrischernoff commented Dec 24, 2015

Strange. This is after a fresh restart? And your homebridge can be normally invoked from the terminal (e.g. just running homebridge) and it runs fine?

@IMNotMax

This comment has been minimized.

Show comment
Hide comment
@IMNotMax

IMNotMax Dec 24, 2015

Yep, interesting case :)
Homebridge works fine, directly or using forever.
I have 18 reboots in the last 24 hours...
I Think it's a permission issue. All other plist files in LaunchAgents are owned by me and not by the root user.
I tried using /Library/LaunchDaemons/ with a different issue. The daemon is launched but the ProgramArguments are not executed.
I think I will reinstall my OS X 10.7.5 during my vacations ;)

IMNotMax commented Dec 24, 2015

Yep, interesting case :)
Homebridge works fine, directly or using forever.
I have 18 reboots in the last 24 hours...
I Think it's a permission issue. All other plist files in LaunchAgents are owned by me and not by the root user.
I tried using /Library/LaunchDaemons/ with a different issue. The daemon is launched but the ProgramArguments are not executed.
I think I will reinstall my OS X 10.7.5 during my vacations ;)

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Dec 24, 2015

@IMNotMax correct, if its in your user library folder it should be owned by the user, not root, thats why its not launching.

Plists only need to be owned by root if they're going into the system folders.

If you've installed the latest Homebridge via NPM -g, it'll be installed in your user folder which means it also runs as your user (and not root) which is why the plist running as root wont open it.

Put it in your user launch agent, make sure your user owns the plist, make sure homebridge runs as your user and make sure your log folders are owned by the user (again put them in your user library folder) and it should all work fine. There's no real reason for homebridge to run as root, its easier to stop and start from terminal without sudo if its not running as root too.

realdannys commented Dec 24, 2015

@IMNotMax correct, if its in your user library folder it should be owned by the user, not root, thats why its not launching.

Plists only need to be owned by root if they're going into the system folders.

If you've installed the latest Homebridge via NPM -g, it'll be installed in your user folder which means it also runs as your user (and not root) which is why the plist running as root wont open it.

Put it in your user launch agent, make sure your user owns the plist, make sure homebridge runs as your user and make sure your log folders are owned by the user (again put them in your user library folder) and it should all work fine. There's no real reason for homebridge to run as root, its easier to stop and start from terminal without sudo if its not running as root too.

@mbnn

This comment has been minimized.

Show comment
Hide comment
@mbnn

mbnn Dec 29, 2015

So uhm, could someone please sum up how to make it auto boot / start? Cause im seeing a lot of different things here. Would love it if someone could post a step by step thing how to make this auto load/ work on OSX.

It would be epic if someone could create a way so it sits in the top next to the time and speaker settings.

mbnn commented Dec 29, 2015

So uhm, could someone please sum up how to make it auto boot / start? Cause im seeing a lot of different things here. Would love it if someone could post a step by step thing how to make this auto load/ work on OSX.

It would be epic if someone could create a way so it sits in the top next to the time and speaker settings.

@IMNotMax

This comment has been minimized.

Show comment
Hide comment
@IMNotMax

IMNotMax Dec 30, 2015

Of course : Follow the steps of this comment #316 (comment)

If you are not friendly with terminal, chmod etc, AND if you don't mind having a terminal window on your OS X, you can just add /usr/local/bin/honebridge to your user at login (Preferences > Users and groups > you user > panel for apps at login > hit the +).
Just a tips : open the finder, Go to folder, type /usr/local/bin/ you will see the homebridge file and you can drag'n drop it on the + window

IMNotMax commented Dec 30, 2015

Of course : Follow the steps of this comment #316 (comment)

If you are not friendly with terminal, chmod etc, AND if you don't mind having a terminal window on your OS X, you can just add /usr/local/bin/honebridge to your user at login (Preferences > Users and groups > you user > panel for apps at login > hit the +).
Just a tips : open the finder, Go to folder, type /usr/local/bin/ you will see the homebridge file and you can drag'n drop it on the + window

@mbnn

This comment has been minimized.

Show comment
Hide comment
@mbnn

mbnn Dec 30, 2015

I've used chrischernoff's way (#316 (comment)) as that actually worked for me :) However, now that it's launched, there is possibly no way to know it's crashed or running, right? (apart from testing an app ofc).

mbnn commented Dec 30, 2015

I've used chrischernoff's way (#316 (comment)) as that actually worked for me :) However, now that it's launched, there is possibly no way to know it's crashed or running, right? (apart from testing an app ofc).

@humac

This comment has been minimized.

Show comment
Hide comment
@humac

humac Dec 30, 2015

@mbnn if u want to know what's going on add logging options to the plist and then you can see errors and the output by viewing the log files

humac commented Dec 30, 2015

@mbnn if u want to know what's going on add logging options to the plist and then you can see errors and the output by viewing the log files

@chrischernoff

This comment has been minimized.

Show comment
Hide comment
@chrischernoff

chrischernoff Dec 31, 2015

@mbnn To get logging, add this after your Program Arguments array in your plist (name the actual log files however you like)

<key>StandardErrorPath</key>
<string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.err.log</string>
<key>StandardOutPath</key>
<string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.out.log</string>

Off the top of my head I don't remember if the launchagent will actually make that folder or those files, so you can do it manually:

  • mkdir ~/Library/Logs/Homebridge to make the folder
  • touch ~/Library/Logs/Homebridge/whateveryounamedthefiles to make each file

A few things I found really helpful to tell if things are actually running:

Check to see if the homebridge LaunchAgent is running (or at least if OSX thinks it successfully ran):

  • launchctl list | grep homebridge

Check to see if any processes are listening on port 51826:

  • netstat -atp tcp | grep -i "listen"
  • lsof -i -P | grep -i "listen"

Also, and this is a big one that took me hours to discover this morning, you might be running into issues with this LaunchAgent if the computer running homebridge connects to the network via WiFi.

I had moved my (typically headless) mac mini away from its hardwired spot in order to hook it up to a monitor temporarily, which meant I had to switch to WiFi. The homebridge LaunchAgent stopped working.

In my mac mini's case, it takes a good 5-10 seconds to establish a wifi connection in my network. This is well after the homebridge agent has started running on login, and as a result it has difficulty connecting to platforms (e.g. Smartthings, Nest) and will hang. This results in a state where it looks like homebridge is running when you run the launch agent check I wrote above, but you will not see any processes listening on port 51826 if you run the other commands I listed.

chrischernoff commented Dec 31, 2015

@mbnn To get logging, add this after your Program Arguments array in your plist (name the actual log files however you like)

<key>StandardErrorPath</key>
<string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.err.log</string>
<key>StandardOutPath</key>
<string>/Users/YOURUSERACCOUNT/Library/Logs/Homebridge/homebridge.out.log</string>

Off the top of my head I don't remember if the launchagent will actually make that folder or those files, so you can do it manually:

  • mkdir ~/Library/Logs/Homebridge to make the folder
  • touch ~/Library/Logs/Homebridge/whateveryounamedthefiles to make each file

A few things I found really helpful to tell if things are actually running:

Check to see if the homebridge LaunchAgent is running (or at least if OSX thinks it successfully ran):

  • launchctl list | grep homebridge

Check to see if any processes are listening on port 51826:

  • netstat -atp tcp | grep -i "listen"
  • lsof -i -P | grep -i "listen"

Also, and this is a big one that took me hours to discover this morning, you might be running into issues with this LaunchAgent if the computer running homebridge connects to the network via WiFi.

I had moved my (typically headless) mac mini away from its hardwired spot in order to hook it up to a monitor temporarily, which meant I had to switch to WiFi. The homebridge LaunchAgent stopped working.

In my mac mini's case, it takes a good 5-10 seconds to establish a wifi connection in my network. This is well after the homebridge agent has started running on login, and as a result it has difficulty connecting to platforms (e.g. Smartthings, Nest) and will hang. This results in a state where it looks like homebridge is running when you run the launch agent check I wrote above, but you will not see any processes listening on port 51826 if you run the other commands I listed.

@mbnn

This comment has been minimized.

Show comment
Hide comment
@mbnn

mbnn Jan 2, 2016

Yes, well, my Mini is connected on LAN :) But was also looking for a way to auto restart it when crashed, or will it do that already? And maybe auto update when restarting? :P

mbnn commented Jan 2, 2016

Yes, well, my Mini is connected on LAN :) But was also looking for a way to auto restart it when crashed, or will it do that already? And maybe auto update when restarting? :P

@AppleTechy

This comment has been minimized.

Show comment
Hide comment
@AppleTechy

AppleTechy Jan 7, 2016

Collaborator

@mbnn Forever well auto restart homebridge when it crashes as for the auto updating thing someone should look into that and add it onto forever that would be pretty neat feature(auto-updating)

Collaborator

AppleTechy commented Jan 7, 2016

@mbnn Forever well auto restart homebridge when it crashes as for the auto updating thing someone should look into that and add it onto forever that would be pretty neat feature(auto-updating)

@uchuujin

This comment has been minimized.

Show comment
Hide comment
@uchuujin

uchuujin Jan 13, 2016

@realdannys I'm not an expert on this stuff, but the error message you posted about failures at boot references "xpcproxy"... which seems to have something to do with inter-process communication. Maybe your issue is there rather than on homebridge itself.

uchuujin commented Jan 13, 2016

@realdannys I'm not an expert on this stuff, but the error message you posted about failures at boot references "xpcproxy"... which seems to have something to do with inter-process communication. Maybe your issue is there rather than on homebridge itself.

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Jan 13, 2016

@uchuujin it was to do with trying to launch incorrectly things owned by root - it all just works neatly if you launch it as your user. Ignore any questions in that post, just copy the plist and run it as user.

realdannys commented Jan 13, 2016

@uchuujin it was to do with trying to launch incorrectly things owned by root - it all just works neatly if you launch it as your user. Ignore any questions in that post, just copy the plist and run it as user.

@rudders

This comment has been minimized.

Show comment
Hide comment
@rudders

rudders Jan 13, 2016

Contributor

Anyone experiencing ETIMEDOUT errors and that use the homebridge-platform-wemo plugin might like to test my forked version of the plugin discussed here rudders/homebridge-platform-wemo#21 (comment) - please update that issue with your findings.

Contributor

rudders commented Jan 13, 2016

Anyone experiencing ETIMEDOUT errors and that use the homebridge-platform-wemo plugin might like to test my forked version of the plugin discussed here rudders/homebridge-platform-wemo#21 (comment) - please update that issue with your findings.

@avavricek

This comment has been minimized.

Show comment
Hide comment
@avavricek

avavricek Jan 15, 2016

I'm having an issue where @realdannys plist loads homebridge fine, but the plugin homebridge-alarmdotcom will not fully work. Console.app says it's loading the accessory. Everything works fine if I execute "homebridge" from terminal, but the plugin fails via loading the plist (selenium-webdriver times out specifically). I feel like it's a permissions issue and applicable to this conversation. That's why i'm starting my questioning here vs the alarmdotcom repo. Thanks all.

avavricek commented Jan 15, 2016

I'm having an issue where @realdannys plist loads homebridge fine, but the plugin homebridge-alarmdotcom will not fully work. Console.app says it's loading the accessory. Everything works fine if I execute "homebridge" from terminal, but the plugin fails via loading the plist (selenium-webdriver times out specifically). I feel like it's a permissions issue and applicable to this conversation. That's why i'm starting my questioning here vs the alarmdotcom repo. Thanks all.

@theboyk

This comment has been minimized.

Show comment
Hide comment
@theboyk

theboyk Feb 9, 2016

Hey guys—got it auto-starting/staying alive (thanks @realdannys), but wondering how I go about gracefully restarting the server (for when I update the config file)? Since it's running in the background, can't control-c to shut it down?

theboyk commented Feb 9, 2016

Hey guys—got it auto-starting/staying alive (thanks @realdannys), but wondering how I go about gracefully restarting the server (for when I update the config file)? Since it's running in the background, can't control-c to shut it down?

@realdannys

This comment has been minimized.

Show comment
Hide comment
@realdannys

realdannys Feb 9, 2016

@theboyk "launchctl unload /your/plist" to stop, "launchctl load /your/plist" to start.

You can put them in bash_profile as aliases (have a Google) so that you can stop homebridge.start, homebridge.stop and homebridge.restart if you want.

realdannys commented Feb 9, 2016

@theboyk "launchctl unload /your/plist" to stop, "launchctl load /your/plist" to start.

You can put them in bash_profile as aliases (have a Google) so that you can stop homebridge.start, homebridge.stop and homebridge.restart if you want.

@theboyk

This comment has been minimized.

Show comment
Hide comment
@theboyk

theboyk Feb 9, 2016

Perfect—didn't realize unloading the plist would actually shut the server down (thought that just launched the server/kept it running). Thanks!

theboyk commented Feb 9, 2016

Perfect—didn't realize unloading the plist would actually shut the server down (thought that just launched the server/kept it running). Thanks!

@OceansCrashing

This comment has been minimized.

Show comment
Hide comment
@OceansCrashing

OceansCrashing Mar 1, 2016

I haven't started using homebridge yet, so I realize this may be a premature comment, but I aim to use Forever to run at startup, and install as a service. If you haven't seen Forever, I highly recommend at least taking a look. I've used it in both Mac and different Linux environments for starting and keeping started shell scripts, as well as node applications.

OceansCrashing commented Mar 1, 2016

I haven't started using homebridge yet, so I realize this may be a premature comment, but I aim to use Forever to run at startup, and install as a service. If you haven't seen Forever, I highly recommend at least taking a look. I've used it in both Mac and different Linux environments for starting and keeping started shell scripts, as well as node applications.

@jnanes

This comment has been minimized.

Show comment
Hide comment
@jnanes

jnanes Sep 6, 2016

I have reviewed everything here and seem to be missing something, I tried many methods, last being "Preferences > Users and groups > you user > panel for apps at login > hit the +).
Just a tips : open the finder, Go to folder, type /usr/local/bin/ you will see the homebridge file and you can drag'n drop it on the + window".

It is failing with a permission error, I tried changing ownership of the homebridge folder to my user and to root but received same error. Also, when launching homebridge, it only works when running "sudo homebridge" instead of just "homebridge".

Jesses-Mac-mini:~ jesse$ /usr/local/lib/node_modules/homebridge/bin/homebridge ; exit;
[9/6/2016, 11:39:23 AM] Loaded plugin: homebridge-nest
[9/6/2016, 11:39:23 AM] Registering platform 'homebridge-nest.Nest'
[9/6/2016, 11:39:23 AM] ---
[9/6/2016, 11:39:23 AM] Loaded config.json with 0 accessories and 1 platforms.
[9/6/2016, 11:39:23 AM] ---
[9/6/2016, 11:39:23 AM] Loading 1 platforms...
[9/6/2016, 11:39:23 AM] Initializing Nest platform...
[9/6/2016, 11:39:23 AM] Fetching Nest devices.
[9/6/2016, 11:39:23 AM] [Error: You did not specify {'token'} or {'clientId','clientSecret','code'}, one set of which is required for the new API]
[9/6/2016, 11:39:23 AM] Falling back to legacy API.
[9/6/2016, 11:39:23 AM] Away for Nest02AA01AB451205QP is: true
[9/6/2016, 11:39:23 AM] Temperature unit for Nest02AA01AB451205QP is: Fahrenheit
[9/6/2016, 11:39:23 AM] Current temperature for Nest02AA01AB451205QP is: 24.18999
[9/6/2016, 11:39:23 AM] Current heating for Nest02AA01AB451205QP is: 0
[9/6/2016, 11:39:23 AM] Current humidity for Nest02AA01AB451205QP is: 53
[9/6/2016, 11:39:23 AM] Target heating for Nest02AA01AB451205QP is: 2
[9/6/2016, 11:39:23 AM] Target temperature for Nest02AA01AB451205QP is: 28.36899
[9/6/2016, 11:39:23 AM] Initializing platform accessory 'Nest02AA01AB451205QP'...
Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

┌────────────┐     
│ xxx-xx-xxx │     
└────────────┘     

fs.js:549
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: EACCES: permission denied, open '/Users/jesse/.homebridge/persist/AccessoryInfo.CC223DE3CE30.json'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.writeFileSync (fs.js:1156:15)
at Object.LocalStorage.persistKeySync (/usr/local/lib/node_modules/homebridge/node_modules/node-persist/local-storage.js:457:12)
at Object.LocalStorage.setItemSync (/usr/local/lib/node_modules/homebridge/node_modules/node-persist/local-storage.js:275:14)
at Object.nodePersist.setItemSync (/usr/local/lib/node_modules/homebridge/node_modules/node-persist/node-persist.js:99:29)
at AccessoryInfo.save (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/model/AccessoryInfo.js:163:11)
at Bridge.Accessory.publish (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:430:23)
at Server._publish (/usr/local/lib/node_modules/homebridge/lib/server.js:92:16)
at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:351:14)
at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:15:19
at /usr/local/lib/node_modules/homebridge-nest/index.js:227:6
at /usr/local/lib/node_modules/homebridge-nest/node_modules/unofficial-nest-api/index.js:232:17
at IncomingMessage. (/usr/local/lib/node_modules/homebridge-nest/node_modules/unofficial-nest-api/index.js:214:25)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:921:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
logout

jnanes commented Sep 6, 2016

I have reviewed everything here and seem to be missing something, I tried many methods, last being "Preferences > Users and groups > you user > panel for apps at login > hit the +).
Just a tips : open the finder, Go to folder, type /usr/local/bin/ you will see the homebridge file and you can drag'n drop it on the + window".

It is failing with a permission error, I tried changing ownership of the homebridge folder to my user and to root but received same error. Also, when launching homebridge, it only works when running "sudo homebridge" instead of just "homebridge".

Jesses-Mac-mini:~ jesse$ /usr/local/lib/node_modules/homebridge/bin/homebridge ; exit;
[9/6/2016, 11:39:23 AM] Loaded plugin: homebridge-nest
[9/6/2016, 11:39:23 AM] Registering platform 'homebridge-nest.Nest'
[9/6/2016, 11:39:23 AM] ---
[9/6/2016, 11:39:23 AM] Loaded config.json with 0 accessories and 1 platforms.
[9/6/2016, 11:39:23 AM] ---
[9/6/2016, 11:39:23 AM] Loading 1 platforms...
[9/6/2016, 11:39:23 AM] Initializing Nest platform...
[9/6/2016, 11:39:23 AM] Fetching Nest devices.
[9/6/2016, 11:39:23 AM] [Error: You did not specify {'token'} or {'clientId','clientSecret','code'}, one set of which is required for the new API]
[9/6/2016, 11:39:23 AM] Falling back to legacy API.
[9/6/2016, 11:39:23 AM] Away for Nest02AA01AB451205QP is: true
[9/6/2016, 11:39:23 AM] Temperature unit for Nest02AA01AB451205QP is: Fahrenheit
[9/6/2016, 11:39:23 AM] Current temperature for Nest02AA01AB451205QP is: 24.18999
[9/6/2016, 11:39:23 AM] Current heating for Nest02AA01AB451205QP is: 0
[9/6/2016, 11:39:23 AM] Current humidity for Nest02AA01AB451205QP is: 53
[9/6/2016, 11:39:23 AM] Target heating for Nest02AA01AB451205QP is: 2
[9/6/2016, 11:39:23 AM] Target temperature for Nest02AA01AB451205QP is: 28.36899
[9/6/2016, 11:39:23 AM] Initializing platform accessory 'Nest02AA01AB451205QP'...
Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

┌────────────┐     
│ xxx-xx-xxx │     
└────────────┘     

fs.js:549
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: EACCES: permission denied, open '/Users/jesse/.homebridge/persist/AccessoryInfo.CC223DE3CE30.json'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.writeFileSync (fs.js:1156:15)
at Object.LocalStorage.persistKeySync (/usr/local/lib/node_modules/homebridge/node_modules/node-persist/local-storage.js:457:12)
at Object.LocalStorage.setItemSync (/usr/local/lib/node_modules/homebridge/node_modules/node-persist/local-storage.js:275:14)
at Object.nodePersist.setItemSync (/usr/local/lib/node_modules/homebridge/node_modules/node-persist/node-persist.js:99:29)
at AccessoryInfo.save (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/model/AccessoryInfo.js:163:11)
at Bridge.Accessory.publish (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:430:23)
at Server._publish (/usr/local/lib/node_modules/homebridge/lib/server.js:92:16)
at Server. (/usr/local/lib/node_modules/homebridge/lib/server.js:351:14)
at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:15:19
at /usr/local/lib/node_modules/homebridge-nest/index.js:227:6
at /usr/local/lib/node_modules/homebridge-nest/node_modules/unofficial-nest-api/index.js:232:17
at IncomingMessage. (/usr/local/lib/node_modules/homebridge-nest/node_modules/unofficial-nest-api/index.js:214:25)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:921:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
logout

@wahlmanj

This comment has been minimized.

Show comment
Hide comment
@OceansCrashing

This comment has been minimized.

Show comment
Hide comment
@OceansCrashing

OceansCrashing Apr 28, 2017

I think the problem is that the script is being run as system, not as you. You'd need to open permissions up to have whoever is running the script be able to read and execute the script. Chmod 644 might work, chmod 755 almost certainly will

OceansCrashing commented Apr 28, 2017

I think the problem is that the script is being run as system, not as you. You'd need to open permissions up to have whoever is running the script be able to read and execute the script. Chmod 644 might work, chmod 755 almost certainly will

@OceansCrashing

This comment has been minimized.

Show comment
Hide comment
@OceansCrashing

OceansCrashing Apr 28, 2017

I set mine up using Node's "Forever" plugin, which lets you specify which user the service is run as, as well as automated recovery and logging if/when the script fails stalls crashes or what have you.

OceansCrashing commented Apr 28, 2017

I set mine up using Node's "Forever" plugin, which lets you specify which user the service is run as, as well as automated recovery and logging if/when the script fails stalls crashes or what have you.

@Patrick1610

This comment has been minimized.

Show comment
Hide comment
@Patrick1610

Patrick1610 May 16, 2017

Hi @chrischernoff

I've followed your plist setup, copied your file and done the chown thing but when try to load i keep getting this message:

Patricks-Mac-Mini:~ patrickvanbavel$ launchctl load ~/Library/LaunchAgents/com.homebridge.server.plist
/Users/patrickvanbavel/Library/LaunchAgents/com.homebridge.server.plist: Invalid or missing service identifier

Any idea what I could be doing wrong. It is not the label/Label thing I read on the internet a lot.

Patrick1610 commented May 16, 2017

Hi @chrischernoff

I've followed your plist setup, copied your file and done the chown thing but when try to load i keep getting this message:

Patricks-Mac-Mini:~ patrickvanbavel$ launchctl load ~/Library/LaunchAgents/com.homebridge.server.plist
/Users/patrickvanbavel/Library/LaunchAgents/com.homebridge.server.plist: Invalid or missing service identifier

Any idea what I could be doing wrong. It is not the label/Label thing I read on the internet a lot.

@mkellsy

This comment has been minimized.

Show comment
Hide comment
@mkellsy

mkellsy Jul 17, 2017

I have successfully auto started homebridge using a few different methods including launchctl on mac. I found that the easiest one to use is supervisord, because it allows you to restart and it has the permissions figured out. (Thank you Minecraft community)

you can install supervisord with this command
sudo pip install supervisor

A nice how to.
Running Supervisor on OSX

Example /usr/local/etc/supervisord.config for homebridge
[program:homebridge]
command=/usr/local/bin/node /usr/local/lib/node_modules/homebridge/bin/homebridge
directory=/usr/local/lib/node_modules/homebridge/bin
user=root
autostart=true
autorestart=true
stdout_logfile=/var/log/homebridge.stdout.log
stderr_logfile=/var/log/homebridge.stderr.log

Once configured you can control homebridge like this
supervisorctl restart homebridge

I hope this helps some people out.

mkellsy commented Jul 17, 2017

I have successfully auto started homebridge using a few different methods including launchctl on mac. I found that the easiest one to use is supervisord, because it allows you to restart and it has the permissions figured out. (Thank you Minecraft community)

you can install supervisord with this command
sudo pip install supervisor

A nice how to.
Running Supervisor on OSX

Example /usr/local/etc/supervisord.config for homebridge
[program:homebridge]
command=/usr/local/bin/node /usr/local/lib/node_modules/homebridge/bin/homebridge
directory=/usr/local/lib/node_modules/homebridge/bin
user=root
autostart=true
autorestart=true
stdout_logfile=/var/log/homebridge.stdout.log
stderr_logfile=/var/log/homebridge.stderr.log

Once configured you can control homebridge like this
supervisorctl restart homebridge

I hope this helps some people out.

@retroneo

This comment has been minimized.

Show comment
Hide comment
@retroneo

retroneo Nov 19, 2017

OK. There are several problems that I have encountered following the instructions for LaunchAgents. All of the following need to be fixed for it to successfully auto launch, and for plugins to work.

  1. Permissions must be correct on ~/LaunchAgents/ folder and the ~/LaunchAgents/com.homebridge.server.plist file.

Type the following four commands in Terminal (replacing username with your username):
sudo chown username ~/LaunchAgents/
sudo chown username ~/LaunchAgents/com.homebridge.server.plist
chmod ~/LaunchAgents/
chmod 600 ~/LaunchAgents/com.homebridge.server.plist

  1. Ensure the plist has the following keys (replacing username with your username). Ensure the full paths are used. The environment variables are essential as otherwise none of the plugins will work.
<key>StandardOutPath</key>
    <string>/Users/username/.homebridge/logfile.log</string>
<key>StandardErrorPath</key>
    <string>/Users/username/.homebridge/logfile.log</string>
<key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
        <key>HOME</key>
        <string>/Users/username</string>
    </dict>

retroneo commented Nov 19, 2017

OK. There are several problems that I have encountered following the instructions for LaunchAgents. All of the following need to be fixed for it to successfully auto launch, and for plugins to work.

  1. Permissions must be correct on ~/LaunchAgents/ folder and the ~/LaunchAgents/com.homebridge.server.plist file.

Type the following four commands in Terminal (replacing username with your username):
sudo chown username ~/LaunchAgents/
sudo chown username ~/LaunchAgents/com.homebridge.server.plist
chmod ~/LaunchAgents/
chmod 600 ~/LaunchAgents/com.homebridge.server.plist

  1. Ensure the plist has the following keys (replacing username with your username). Ensure the full paths are used. The environment variables are essential as otherwise none of the plugins will work.
<key>StandardOutPath</key>
    <string>/Users/username/.homebridge/logfile.log</string>
<key>StandardErrorPath</key>
    <string>/Users/username/.homebridge/logfile.log</string>
<key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
        <key>HOME</key>
        <string>/Users/username</string>
    </dict>
@stale

This comment has been minimized.

Show comment
Hide comment
@stale

stale bot May 18, 2018

This issue has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

stale bot commented May 18, 2018

This issue has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

@stale stale bot added the stale label May 18, 2018

@stale stale bot closed this Jun 1, 2018

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