Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Created November 25, 2009 14:18
Show Gist options
  • Save ThisIsMissEm/242732 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/242732 to your computer and use it in GitHub Desktop.
A very basic daemon for Node.js
#! /bin/sh
CUR_DIR=$PWD
PID_FILE="$CUR_DIR/node.pid"
if [ $1 = "start" ]; then
if [ -e $PID_FILE ]; then
echo "Node.js is already running."
else
echo "Starting Node Server"
(node $2 &) > /dev/null && ps -C node | cut -d"
" -f 2 | cut -d" " -f 1 > $PID_FILE
fi
elif [ $1 = "stop" ]; then
if [ ! -e $PID_FILE ]; then
echo "Node.js is not running."
else
echo "Stopping Node Server"
kill `cat $PID_FILE`
rm -rf $PID_FILE
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment