Skip to content

Instantly share code, notes, and snippets.

@ruudud
Created December 14, 2012 12:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ruudud/4285257 to your computer and use it in GitHub Desktop.
Save ruudud/4285257 to your computer and use it in GitHub Desktop.
BusterJS and PhantomJS start/stop script, handy for Jenkins/CI
#!/bin/bash
#
# Depends on buster.js and phantom.js being installed
#
BUSTERPATH_OSX="/usr/local/lib/node_modules/buster"
BUSTERPATH_GNU="/usr/lib/node_modules/buster"
BUSTER_PHANTOMSCRIPT="script/phantom.js"
BUSTER_CMD="buster-server"
PHANTOM_CMD="phantomjs"
command -v $BUSTER_CMD > /dev/null || { echo "Buster not found"; exit 1; }
command -v $PHANTOM_CMD > /dev/null || { echo "Phantomjs not found"; exit 1; }
if [ -d $BUSTERPATH_GNU ]; then
BUSTER_PHANTOMSCRIPT_PATH="$BUSTERPATH_GNU/$BUSTER_PHANTOMSCRIPT";
elif [ -d $BUSTERPATH_OSX ]; then
BUSTER_PHANTOMSCRIPT_PATH="$BUSTERPATH_OSX/$BUSTER_PHANTOMSCRIPT"
else
echo "Buster script not found"
exit 1
fi
get_buster_pid (){
echo `ps aux|grep $BUSTER_CMD|grep node|awk '{ print $2 }'`
}
get_phantom_pid (){
echo `ps aux|grep $PHANTOM_CMD|grep buster|awk '{ print $2 }'`
}
case "$1" in
"start")
echo "Starting buster server…"
buster-server &
sleep 4 # It takes a while for buster server to start
echo "Starting phantomjs and pointing it at buster…"
phantomjs $BUSTER_PHANTOMSCRIPT_PATH &>/dev/null &
;;
"stop")
echo "Killing buster and phantom servers"
kill `get_buster_pid`
kill `get_phantom_pid`
;;
*)
echo "Usage:
$0 start|stop"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment