My Blög

node.js and forever and init.d

2012-12-30

Here’s how I set up init.d on my Raspberry to launch forever at start. Forever then keeps my node.js weather server running. Big thanks to @ikr for his help!

#!/bin/bash
 
### BEGIN INIT INFO
# Provides:                     weathernode
# Required-Start:               $local_fs
# X-UnitedLinux-Should-Start:
# Required-Stop:                $local_fs
# X-UnitedLinux-Should-Stop:
# Default-Start:                2 3 4 5
# Default-Stop:                 0 1 6
# Short-Description:            weathernode
# Description:                  weathernode
### END INIT INFO
 
case "$1" in
    start)
        su - pi -c "forever start -al /var/log/weathernode.log --spinSleepTime 5000 --sourceDir=/home/pi/apps/weathernod
e server.js"
        ;;
    stop)
        su - pi -c "forever stopall"
        forever stopall
        ;;
    restart)
        su - pi -c "forever restartall"
        forever restartall
        ;;
    status)
        su - pi -c "forever list"
        forever list
        ;;
esac

Per Ejeklint in disguise

Writings by Per Ejeklint, living and working in Stockholm, Sweden. Follow me on Twitter!