The "problem" some users have had (including me), where Homebridge won't run successfully at start-up, but will run fine when started manually, is that the Indigo web server isn't yet fully alive when Homebridge is launched in this manner. This results in a blank set of devices, because they couldn't be loaded from Indigo. The solution is to make sure that the web server is running as part of the launch process, via a script.
The first step is to follow the great instructions in this sub-forum for installing and setting up Homebridge and Homebridge-Indigo. I made a couple of tweaks:
- I wanted to run Homebridge using a different user account (as I do with Indigo)
- Rather than starting at login, I wanted Homebridge to start when the computer boots
Here's what I did, step by step:
- 1. Create local user homebridge, in group Indigo, with home directory
Disable log in for user
2. In homebridge user directory, create .homebridge (if you followed the instructions, just move this from your user directory)
3. Place copy of conf.json in this directory
4. In /Library/Logs, create Homebridge directory
5. Set owner (chown) of the Homebridge directory to homebridge:indigo
6. Place copy of launch.sh in /Users/homebridge (this is your start-up script; see below)
7. Make launch.sh executable (sudo chmod ug+x launch.sh)
8. Set owner (chown) for all files under homebridge to homebridge:indigo
9. Copy com.homebridge.server.plist to /Library/LaunchDaemons (tweaks for user this will run under, logging location, and method of launch)
10. Set owner (chown) this plist file to root:wheel
11. sudo launchctl load /Library/LaunchDaemons/com.homebridge.server.plist
Here's my launch.sh file:
- Code: Select all
#!/bin/sh
export PATH=/usr/local/bin:/usr/bin:/opt/local/bin:$PATH
result="$(curl --silent --head [b]http://localhost:8176/[/b] | head -n 1 | egrep -e 'HTTP/[0-9]\.[0-9] (2..|3..|401)')"
echo $result >/Library/Logs/Homebridge/homebridge.out 2>&1
case $result in
'')
exit 1
;;
*)
exec homebridge -U /Users/homebridge/.homebridge >>/Library/Logs/Homebridge/homebridge.out 2>&1
esac
Replace http://localhost:8176/ with the URL and port your server runs on — mine is http://indigo.myservername.private:8000.
The launch script above is where the "magic" happens. Using the command-line utility CURL, it looks for a success response (2xx or 3xx) from the server; or, it looks for a request to authenticate (401) — your username and password aren't required, because it can tell the difference between an authentication challenge for a valid page and a not-found error. If any one of these success responses are received, it will launch Homebridge. If not, Launchd will wait and try again until the server is launched.
Here's my com.homebridge.server.plist file:
- Code: Select all
<?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>UserName</key>
<string>homebridge</string>
<key>GroupName</key>
<string>indigo</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<true/>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>StandardErrorPath</key>
<string>/Library/Logs/Homebridge/homebridge.err</string>
<key>StandardOutPath</key>
<string>/Library/Logs/Homebridge/homebridge.out</string>
<key>Label</key>
<string>com.homebridge.server</string>
<key>ProgramArguments</key>
<array>
<string>/Users/homebridge/launch.sh</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin/:$PATH</string>
</dict>
</dict>
</plist>
Replace the UserName and GroupName with the right values for your set-up.
I hope this helps someone out!