Last active
August 29, 2015 04:34
-
-
Save qigao/1f214958d18212c144ab to your computer and use it in GitHub Desktop.
Phantomjs startup script for Centos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# chkconfig: 35 99 99 | |
# description: Script for starting phantomjs. | |
# | |
. /etc/rc.d/init.d/functions | |
USER="phantomjs" | |
DAEMON="/usr/local/phantomjs/bin/phantomjs --webdriver=4444" | |
LOG_FILE="/var/log/phantomjs/main.log" | |
do_start() | |
{ | |
echo -n $"Starting PhantomJS : " | |
runuser -l "$USER" -c "$DAEMON >> $LOG_FILE &" && echo_success || echo_failure | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] | |
} | |
do_stop() | |
{ | |
echo -n $"Stopping PhantomJS : " | |
pid=`ps -aefw | grep "$DAEMON" | grep -v " grep " | awk '{print $2}'` | |
kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
restart) | |
do_stop | |
do_start | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart}" | |
RETVAL=1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment