15 Commits

Author SHA1 Message Date
Jon Maddox
febed4cae6 derped the ignore 2015-10-24 11:34:41 -04:00
Jon Maddox
17f13a51a4 merge master 2015-10-24 11:14:36 -04:00
Jon Maddox
2b11db4560 guard 2015-09-18 10:10:09 -04:00
Jon Maddox
cf885b6d29 Merge branch 'master' into osx-launchd 2015-09-17 19:39:39 -04:00
Jon Maddox
267470c871 Merge branch 'master' into osx-launchd 2015-09-16 10:49:13 -04:00
Jon Maddox
ae2d53262f document the new scripts 2015-09-14 23:56:22 -04:00
Jon Maddox
241b22db87 warn pi users 2015-09-14 23:46:08 -04:00
Jon Maddox
8d94366e3c do it 2015-09-14 23:39:46 -04:00
Jon Maddox
950e6a8211 support install/uninstall on linux with SysVinit 2015-09-14 23:39:42 -04:00
Jon Maddox
f3cab9a529 SysVinit template for linux 2015-09-14 23:39:18 -04:00
Jon Maddox
25981deac4 conditionalize the install/uninstall scripts to support linux or darwin. 2015-09-14 23:20:13 -04:00
Jon Maddox
6540c25baf add launchd plist 2015-09-14 22:54:01 -04:00
Jon Maddox
6f71faf355 add Scripts to Rule Them All 2015-09-14 22:53:49 -04:00
Jon Maddox
8131f6936e add forever env configs 2015-09-14 22:53:32 -04:00
Jon Maddox
ac0c967ec0 ignore logs dir 2015-09-14 22:53:05 -04:00
12 changed files with 284 additions and 11 deletions

2
.gitignore vendored
View File

@@ -15,6 +15,6 @@ npm-debug.log
config.json
config.test.json
persist/
log/
.AppleDouble

View File

@@ -60,23 +60,17 @@ First, clone this repo:
$ git clone https://github.com/nfarina/homebridge.git
$ cd homebridge
$ npm install
$ script/bootstrap
**Note**: You'll need to have NodeJS version 0.12.x or better installed for required submodule `HAP-NodeJS` to load.
**Node**: You'll need to have NodeJS version 0.12.x or better installed for required submodule `HAP-NodeJS` to load as well as the `forever` node package..
The server won't do anything until you've edited your `config.json` file containing your home devices (or _accessories_ in HomeKit parlance) or platforms you wish to make available to iOS. The sample configuration has been copied for you into `config.json`. It includes declarations for all supported accessories and platforms. Remove everything except for the accessories and platforms you'll be using.
Now you should be able to run the homebridge server:
$ cd homebridge
$ npm run start
Starting Homebridge server...
Couldn't find a config.json file [snip]
$ script/server
The server won't do anything until you've created a `config.json` file containing your home devices (or _accessories_ in HomeKit parlance) or platforms you wish to make available to iOS. You can start by copying and modifying the included `config-sample.json` file which includes declarations for all supported accessories and platforms.
Once you've added your devices and/or platforms, you should be able to run the server again and see them initialize:
$ npm run start
Starting Homebridge server...
Loading 6 accessories...
[Speakers] Initializing 'Sonos' accessory...
@@ -89,6 +83,22 @@ Once you've added your devices and/or platforms, you should be able to run the s
Your server is now ready to receive commands from iOS.
# Installing Homebridge to Run at Boot and in the Background
Homebridge can be run at boot and in the background on OS X and any Linux variation that uses SysVinit (/etc/init.d scripts) to launch services. To install homebridge as
a service:
$ script/install
It should load for you in the background. You can find logs in `log/logs.log`. To uninstall it you can run `script/uninstall`. To restart it you can run `script/restart`.
# Upgrading
If you want to upgrade homebridge, simply run:
$ script/upgrade
It will pull the newest version from the repo on GitHub and restart itself.
# Adding your devices to iOS
HomeKit is actually not an app; it's a "database" similar to HealthKit and PassKit. But where HealthKit has the companion _Health_ app and PassKit has _Passbook_, Apple has supplied no app for managing your HomeKit database (at least [not yet](http://9to5mac.com/2015/05/20/apples-planned-ios-9-home-app-uses-virtual-rooms-to-manage-homekit-accessories/)). However, the HomeKit API is open for developers to write their own apps for adding devices to HomeKit.

33
script/bootstrap Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
set -e
if ! test $(which forever)
then
echo
echo "!!!!"
echo "You don't have forever installed. You need to install it first."
echo
echo "Just install it with this command: "
echo 'sudo npm install forever -g'
echo
exit 1
fi
mkdir -p log
echo "Installing packages..."
if [[ "$OSTYPE" == "linux*" ]]; then
echo "This might take a while on a Raspberry Pi..."
fi
npm install > /dev/null 2>&1
if [ ! -f config.json ]
then
echo
echo "==> Creating your config. Please edit config.json."
echo
cp config-sample.json config.json
fi
echo "Finished setting up Homebridge! run it with script/server or install it with script/install."

44
script/install Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/sh
set -e
echo "Installing Homebridge..."
APP_PATH=`pwd`
FOREVER_PATH=`which forever || true`
USER_NAME=`whoami`
if [[ "$OSTYPE" == "linux*" ]]; then
## install for linux
# copy SysVinit script to the correct path.
sudo cp startup/homebridge /etc/init.d/homebridge
# set exec permissions on script.
sudo chmod +x /etc/init.d/homebridge
# Set the current path for where the app lives.
sudo sed -i '' -e "s#%PATH%#$APP_PATH#g" /etc/init.d/homebridge
# Set the path for where the forever lives.
sudo sed -i '' -e "s#%FOREVER_PATH%#$FOREVER_PATH#g" /etc/init.d/homebridge
# Start it.
sudo /etc/init.d/homebridge start
# tell it to launch at boot
sudo update-rc.d homebridge defaults
elif [[ "$OSTYPE" == "darwin"* ]]; then
## install for OS X
# copy template plist to the correct path.
cp startup/org.homebridge.plist ~/Library/LaunchAgents/org.homebridge.plist
# Set the current user for the script to run as.
sed -i '' -e "s#%USER%#$USER_NAME#g" ~/Library/LaunchAgents/org.homebridge.plist
# Set the current path for where the app lives.
sed -i '' -e "s#%PATH%#$APP_PATH#g" ~/Library/LaunchAgents/org.homebridge.plist
# Tell launchd to start it.
launchctl load -w -F ~/Library/LaunchAgents/org.homebridge.plist
fi

4
script/restart Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
script/uninstall
script/install

12
script/server Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
FOREVER_PATH=`which forever`
test -z "$NODE_ENV" &&
export NODE_ENV='development'
if [ "$NODE_ENV" = "development" ]; then
$FOREVER_PATH -f startup/forever/development.json
else
$FOREVER_PATH start startup/forever/production.json
fi

22
script/uninstall Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
echo "Uninstalling Homebridge..."
# make forever stop the app.
forever stop homebridge > /dev/null 2>&1
if [[ "$OSTYPE" == "linux*" ]]; then
## uninstall for linux
# stop the service.
sudo /etc/init.d/homebridge stop
# remove the service from launching at boot.
sudo update-rc.d -f homebridge remove
elif [[ "$OSTYPE" == "darwin"* ]]; then
## uninstall for OS X
# tell launchd to stop the process.
launchctl unload ~/Library/LaunchAgents/org.homebridge.plist
# remove the launchd script.
rm ~/Library/LaunchAgents/org.homebridge.plist
fi

8
script/upgrade Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
echo "Updating from GitHub..."
BRANCH=$(git rev-parse --abbrev-ref HEAD)
git pull origin $BRANCH
npm update
script/restart

View File

@@ -0,0 +1,4 @@
{
"append": true,
"script": "app.js"
}

View File

@@ -0,0 +1,7 @@
{
"uid": "homebridge",
"append": true,
"script": "app.js",
"outFile": "log/logs.log",
"errFile": "log/error.log"
}

88
startup/homebridge Normal file
View File

@@ -0,0 +1,88 @@
### BEGIN INIT INFO
# If you wish the Daemon to be lauched at boot / stopped at shutdown :
#
# On Debian-based distributions:
# INSTALL : update-rc.d scriptname defaults
# (UNINSTALL : update-rc.d -f scriptname remove)
#
# On RedHat-based distributions (CentOS, OpenSUSE...):
# INSTALL : chkconfig --level 35 scriptname on
# (UNINSTALL : chkconfig --level 35 scriptname off)
#
# chkconfig: 2345 90 60
# Provides: %PATH%/app.js
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: forever running %PATH%/app.js
# Description: %PATH%/app.js
### END INIT INFO
#
# initd a node app
# Based on a script posted by https://gist.github.com/jinze at https://gist.github.com/3748766
#
if [ -e /lib/lsb/init-functions ]; then
# LSB source function library.
. /lib/lsb/init-functions
fi;
pidFile="/var/run/homebridge.pid"
logFile="%PATH%/log/logs.log"
command="node"
nodeApp="%PATH%/app.js"
foreverApp="%FOREVER_PATH%"
start() {
echo "Starting $nodeApp"
# Notice that we change the PATH because on reboot
# the PATH does not include the path to node.
# Launching forever with a full path
# does not work unless we set the PATH.
PATH=/usr/local/bin:$PATH
export NODE_ENV=production
#PORT=80
$foreverApp start --pidFile $pidFile -l $logFile -a -d -c "$command" $nodeApp
RETVAL=$?
}
restart() {
echo -n "Restarting $nodeApp"
$foreverApp restart $nodeApp
RETVAL=$?
}
stop() {
echo -n "Shutting down $nodeApp"
$foreverApp stop $nodeApp
RETVAL=$?
}
status() {
echo -n "Status $nodeApp"
$foreverApp list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL

View File

@@ -0,0 +1,41 @@
<?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>org.homebridge</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin/:/usr/bin:$PATH</string>
<key>NODE_ENV</key>
<string>production</string>
</dict>
<key>Program</key>
<string>script/server</string>
<key>AbandonProcessGroup</key>
<false/>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>WorkingDirectory</key>
<string>%PATH%</string>
<key>StandardErrorPath</key>
<string>/Users/%USER%/Library/Logs/homebridge.log</string>
<key>StandardOutPath</key>
<string>/Users/%USER%/Library/Logs/homebridge.log</string>
</dict>
</plist>