Skip to content

Commit

Permalink
Added sample init script
Browse files Browse the repository at this point in the history
Closes #65.
  • Loading branch information
bakape authored and lalcmellkmal committed Jul 28, 2014
1 parent 16d4175 commit 3a03c12
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Production:
* config.DAEMON support is broken for now
* You can update client code & hot.js on-the-fly with `node server/kill.js`
* For nginx hosting/reverse proxying, refer to docs/nginx.conf.example
* For a sample init script, refer to docs/doushio.initscript.example

Dependencies:

Expand Down
74 changes: 74 additions & 0 deletions docs/doushio.initscript.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: doushio
# Required-Start: redis-server
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Custom init wrapper script for the doushio image board node.js server
# Description: Custom init wrapper script for the doushio image board node.js server
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="doushio image board node.js server"
NAME=doushio
USER=doushio
DOUSHIO_DIR=/home/${USER}/server
NODE=/usr/bin/node
DAEMON=${DOUSHIO_DIR}/server/server.js
SCRIPTNAME=/etc/init.d/$NAME
LOG=/var/log/doushio.error.log

do_start()
{
if ps -p $(cat ${DOUSHIO_DIR}/doushio.pid) >/dev/null; then
do_stop
fi
if [ ! -f $LOG ]; then
touch $LOG
chown $USER $LOG
fi
su -l $USER -c "echo [`date -u +%Y-%m-%dT%T.%3NZ`] Starting >> $LOG
cd $DOUSHIO_DIR
$NODE server/server.js 1>/dev/null 2>>$LOG &
echo \$! > doushio.pid
$NODE archive/daemon.js 1>/dev/null 2>>$LOG &
echo \$! > doushio.archive.pid" $USER
}

do_stop()
{
kill $(cat ${DOUSHIO_DIR}/doushio.archive.pid)
kill $(cat ${DOUSHIO_DIR}/doushio.pid)
su -l $USER -c "echo [`date -u +%Y-%m-%dT%T.%3NZ`] Stopping >> $LOG"
}

do_reload()
{
su -l $USER -c "cd $DOUSHIO_DIR; $NODE server/kill.js --pid doushio.pid"
}

case "$1" in
start)
echo "Starting $DESC"
do_start
;;
stop)
echo "Stopping $DESC"
do_stop
;;
restart)
echo "Restarting $DESC"
do_start
;;
reload)
echo "Reloading $DESC"
do_reload
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

:

0 comments on commit 3a03c12

Please sign in to comment.