Skip to content

Instantly share code, notes, and snippets.

@rpossan
Forked from ultimagriever/install.sh
Created June 28, 2017 18:50
Show Gist options
  • Save rpossan/909b563a0cd3a141747ef4c1e3b85831 to your computer and use it in GitHub Desktop.
Save rpossan/909b563a0cd3a141747ef4c1e3b85831 to your computer and use it in GitHub Desktop.
Start PhantomJS server as a Linux service
export TMPDIR=/tmp/
cd /usr/local/lib
mkdir phantom
cd phantom
wget https://gist.githubusercontent.com/ultimagriever/72fcb3e4446460638d65aecd2fbee98c/raw/9d915c60921219900b60c64cf5379c54d63ca43c/restart.sh
wget https://gist.githubusercontent.com/ultimagriever/72fcb3e4446460638d65aecd2fbee98c/raw/9d915c60921219900b60c64cf5379c54d63ca43c/start.sh
wget https://gist.githubusercontent.com/ultimagriever/72fcb3e4446460638d65aecd2fbee98c/raw/9d915c60921219900b60c64cf5379c54d63ca43c/status.sh
wget https://gist.githubusercontent.com/ultimagriever/72fcb3e4446460638d65aecd2fbee98c/raw/9d915c60921219900b60c64cf5379c54d63ca43c/stop.sh
chmod +x *.sh
ln -s /usr/local/lib/phantom/restart.sh /usr/local/bin/phantom-restart
ln -s /usr/local/lib/phantom/start.sh /usr/local/bin/phantom-start
ln -s /usr/local/lib/phantom/status.sh /usr/local/bin/phantom-status
ln -s /usr/local/lib/phantom/stop.sh /usr/local/bin/phantom-stop
phantom-start
#!/bin/bash
phantom-stop
phantom-start
exit 1
#!/bin/bash
SERVICE_NAME="phantom"
FOLDER="/usr/local/bin"
KEYWORD="countdown"
PROC=`ps -ef | grep $SERVICE_NAME | grep $KEYWORD | grep -v grep | awk -F" " '{ print $2 }'`;
if [ "$PROC" ]; then
echo "$SERVICE_NAME is already running."
echo "If you would like to restart, please run '${SERVICE_NAME}-restart'."
exit
fi
CORES=$(cat /proc/cpuinfo | grep cores | awk -F '[^0-9]*' '$0=$2')
echo "Starting $CORES servers..."
for i in `seq 1 $CORES`
do
PORT=$(expr 4000 + $i)
nohup /usr/local/bin/phantomjs /var/www/html/node-countdown-gif/countdown-generator/generate.js $PORT &
done
echo "$CORES servers started."
exit
#!/bin/bash
PORTS=`ps -ef | grep phantom | grep countdown | grep -v grep | awk -F" " '{ print $10 }'`;
if [ "$PORTS" ]; then
echo "Service running on the following ports:"
while read -r line; do
echo $line
done <<< "$PORTS"
fi
exit 1
#!/bin/bash
SERVICE_NAME="phantom"
KEYWORD="countdown"
echo "Stopping $SERVICE_NAME..."
killall phantomjs
sleep 5
echo "$SERVICE_NAME stopped."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment