Skip to content

Instantly share code, notes, and snippets.

@ThePixelDeveloper
Created June 11, 2013 15:55
Show Gist options
  • Save ThePixelDeveloper/5758093 to your computer and use it in GitHub Desktop.
Save ThePixelDeveloper/5758093 to your computer and use it in GitHub Desktop.
init.d file for selenium
#!/bin/bash
### BEGIN INIT INFO
# Provides: selenium
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start selenium at boot time
# Description: Enable service provided by selenium.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DISPLAY_ID=":99"
RUN_AS=root
XVFB=/usr/bin/Xvfb
XVFB_ARGS="$DISPLAY_ID -screen 0 1280x1024x24 -fbdir /var/run -ac"
XVFB_PID_FILE=/var/run/xvfb.pid
JAVA_BIN=/usr/bin/java
SELENIUM_DIR=/opt/selenium
SELENIUM_PID_FILE="$SELENIUM_DIR/selenium.pid"
SELENIUM_JAR_FILE="$SELENIUM_DIR/selenium-server-standalone-2.33.0.jar"
SELENIUM_LOG_FILE="$SELENIUM_DIR/selenium.log"
SELENIUM_DAEMON_OPTS=" -client -jar $SELENIUM_JAR_FILE -log $SELENIUM_LOG_FILE"
export DISPLAY="$DISPLAY_ID.0"
set -e
. /lib/lsb/init-functions
case "$1" in
start)
if status_of_proc -p $SELENIUM_PID_FILE "$SELENIUM_JAR_FILE" $SELENIUM_JAR_FILE > /dev/null; then
log_progress_msg "Service already running"
else
log_daemon_msg "Starting virtual X frame buffer"
log_progress_msg "xvfb"
start-stop-daemon -c $RUN_AS --start --quiet --pidfile $XVFB_PID_FILE --make-pidfile --background --exec $XVFB -- $XVFB_ARGS
log_daemon_msg "Starting Selenium server"
log_progress_msg "selenium"
start-stop-daemon -c $RUN_AS --start --quiet --background --pidfile $SELENIUM_PID_FILE --make-pidfile --exec $JAVA_BIN -- $SELENIUM_DAEMON_OPTS
fi
;;
stop)
if status_of_proc -p $SELENIUM_PID_FILE "$SELENIUM_JAR_FILE" $SELENIUM_JAR_FILE > /dev/null; then
log_daemon_msg "Stopping Selenium server"
log_progress_msg "selenium"
start-stop-daemon --stop --pidfile $SELENIUM_PID_FILE
log_daemon_msg "Stopping virtual X frame buffer"
log_progress_msg "xvfb"
start-stop-daemon --stop --pidfile $XVFB_PID_FILE
else
log_progress_msg "Service not running"
fi
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
status)
status_of_proc -p $SELENIUM_PID_FILE "$SELENIUM_JAR_FILE" $SELENIUM_JAR_FILE && exit 0 || exit $?
;;
*)
N=/etc/init.d/selenium
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment