Skip to content

Commit

Permalink
added startup script that uses forever
Browse files Browse the repository at this point in the history
  • Loading branch information
Juul committed Dec 22, 2014
1 parent facdfa1 commit 9bfee4a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ Swipe a new card and run the grant_access_to_last_failed_attempt.js script to gr

# Autostart on boot

## With forever (autostart on fail)

```
sudo cp doorjam.initd.with-forever /etc/init.d/doorjam
sudo update-rc.d doorjam defaults
```

Now edit the /etc/init.d/doorjam file to ensure all paths are correct.

## Without forever (no autostart on fail)

```
sudo cp doorjam.init /etc/init.d/doorjam
sudo cp doorjam.initd.no-forever /etc/init.d/doorjam
sudo update-rc.d doorjam defaults
```

Now edit the /etc/init.d/doorjam file to ensure all paths are correct.

# Granting access remotely

Change the IP, path and <name and contact info of new user>:
Expand Down
File renamed without changes.
74 changes: 74 additions & 0 deletions doorjam.initd.with-forever
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: doorjam
# Required-Start: $remote_fs dbus
# Required-Stop: $remote_fs dbus
# Should-Start: $syslog
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Meatspace firewall
# Description: Controls door access for sudo room / omni
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

pidFile="/var/run/doorjam.pid"
logFile="/var/log/doorjam.log"

command="node"
nodeApp="/root/doorjam/index.js"
foreverApp="/usr/local/bin/forever"

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

0 comments on commit 9bfee4a

Please sign in to comment.