Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoca committed Mar 27, 2014
0 parents commit 1d73771
Show file tree
Hide file tree
Showing 10 changed files with 606 additions and 0 deletions.
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Role Name
========

This role installs the selenium server

Requirements
------------

This role requires the java, currently to supply this it depends on the oracle_java7 role

Role Variables
--------------

# info for downloading seleinum verion
download_url: http://selenium.googlecode.com/files/{{jar_file}}
jar_file: selenium-server-standalone-{{server_version}}.jar
server_version: 2.39.0

# roles can be: standalone, hub or node
sel_role: standalone

##### optional vars #####
# uri for slaves to find hub server
hub: ''
# jvm settings
java_opts: ''
# extra arguments to selenium jar
extra_args: ''
# specific port for selemium server (uses selenium role default otherwise)
port: ''



Dependencies
------------

It depends on the oracle_java7 role

License
-------

GPLv2

Author Information
------------------

[email protected]
11 changes: 11 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
download_url: http://selenium.googlecode.com/files/{{jar_file}}
jar_file: selenium-server-standalone-{{server_version}}.jar
server_version: 2.39.0

sel_role: standalone

hub: ''
java_opts: ''
extra_args: ''
port: ''
1 change: 1 addition & 0 deletions files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.jar
7 changes: 7 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

---
- name: selenium_started
service: name=selenium_{{sel_role}} state=started enabled=yes

- name: selenium_reload
service: name=selenium_{{sel_role}} state=reloaded
17 changes: 17 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
galaxy_info:
author: Brian Coca
description: Installs and configures Selenium server in any of 3 modes (standalone,hub or node)
company:
license: GPLv2
min_ansible_version: 1.5
platforms:
- name: Ubuntu
versions:
- precise
- saucy
categories:
- system
- web
dependencies:
- briancoca.oracle_java7
25 changes: 25 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Download selenium on 'master' if we don't have it
connection: local
sudo: False
get_url: url={{download_url}} dest={{cur_dir}}/{{jar_file}} force=no

- name: Copy selenium into place
copy: src={{jar_file}} dest=/usr/local/lib/ owner=root group=root mode=644

- name: Install Config
template: src=defaults.j2 dest=/etc/default/selenium_{{sel_role}} owner=root group=root mode=644
tags: ['config']
notify: selenium_reload

- name: Install init script
template: src=init.j2 dest=/etc/init.d/selenium_{{sel_role}} owner=root group=root mode=755
tags: ['config']
notify: selenium_started

- name: Install browser
apt: name={{item}}
when: sel_role != 'hub'
with_items:
- xvfb
- firefox
5 changes: 5 additions & 0 deletions templates/defaults.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
JAVA_OPTS="{{java_opts}}"
ROLE="{{sel_role}}"
HUB="{{hub}}"
PORT="{{port}}"
EXTRA_ARGS="{{extra_args}}"
153 changes: 153 additions & 0 deletions templates/init.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/sh
#
# /etc/init.d/selenium_{{sel_role}} -- startup script for selenium test server
#
### BEGIN INIT INFO
# Provides: selenium_{{sel_role}}
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Selenium {{sel_role}}.
# Description: Start the Selenium {{sel_role}} server.
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=selenium_{{sel_role}}
DESC="Selenium test server {{sel_role}}"
DEFAULT="/etc/default/${NAME}"
SE_PID="/var/run/${NAME}.pid"
JVM_TMP="/var/tmp/${NAME}_app"

if [ `id -u` -ne 0 ]; then
# no user change?
echo "You need root privileges to run this script"
exit 1
fi

# Make sure it is started with system locale
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG
fi

. /lib/lsb/init-functions

if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi

# overwrite settings with default file
if [ -f "${DEFAULT}" ]; then
. "${DEFAULT}"
fi

# overridable defaults
SE_USER=${SE_USER:-"nobody"}
SE_GROUP=${SE_GROUP:-"nogroup"}
JAR_ARGS=${JAR_ARGS:-""}
JAVA_OPTS=${JAVA_OPTS:-""}


SYSTEM_JAVA=$(/usr/sbin/update-alternatives --query java|grep Value|cut -f 2 -d":")
if [ -z "$JAVA_HOME" -a ! -z "${SYSTEM_JAVA}" ]; then
JAVA_HOME=$(dirname "${SYSTEM_JAVA}")
JAVA_HOME=${JAVA_HOME%/bin}
fi
export JAVA_HOME JAVA_TMP JAVA_OPTS

case $1 in
start)
$0 status
if [ $? -eq 0 ]; then
log_daemon_msg "No need to start another!"
exit 0
fi

log_daemon_msg "Starting $DESC" "$NAME"

# Some validation
if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JAVA found - please set JAVA_HOME"
exit 1
fi
umask 022
# Clean JVM_TMP directory
if [ -d "$JVM_TMP" ]; then
rm -rf "${JVM_TMP}" || {
log_failure_msg "could not clean JVM temporary directory"
exit 1
}
fi
install -o ${SE_USER} -g ${SE_GROUP} -d ${JVM_TMP}

if [ ! -z "${ROLE}" ]; then
JAR_ARGS="-role ${ROLE}"
fi
if [ ! -z "${HUB}" ]; then
JAR_ARGS="${JAR_ARGS} -hub ${HUB}"
fi

if [ ! -z "${PORT}" ]; then
JAR_ARGS="${JAR_ARGS} -port ${PORT}"
fi

start-stop-daemon --start \
--background \
--pidfile "${SE_PID}" \
--make-pidfile \
--user "${SE_USER}" \
--group "${SE_GROUP}" \
--startas ${NAME} \
--exec ${JAVA_HOME}/bin/java -- ${JAVA_OPTS} -jar /usr/local/lib/{{jar_file}} ${JAR_ARGS} ${EXTRA_ARGS} 2>&1 \
| logger -t "${NAME}"
;;
stop)
log_daemon_msg "Stopping ${DESC}" "${NAME}"
$0 status
if [ $? -eq 0 ]; then
start-stop-daemon --stop \
--pidfile "${SE_PID}" \
--name ${NAME} \
--retry=TERM/30/KILL/5
rc=$?
if [ $? -eq 0 ]; then
if [ -f "${SE_PID}" ]; then
rm "${SE_PID}"
fi
log_daemon_msg "${NAME} stopped"
fi
return ${rc}
fi
;;
status)
start-stop-daemon --status --pidfile "${SE_PID}" --name ${NAME}
rc=$?
case $rc in
0) msg="$NAME is running with pid: $( cat ${SE_PID})." ;;
1) msg="$NAME is not running but pid file exists." ;;
3) msg="$NAME is not running.";;
4) msg="Unable to determine status of ${NAME}";;
esac
log_daemon_msg $msg
return $rc
;;
version)
echo "${NAME} {{server_version}}"
;;
restart)
$0 stop || true
$0 start
;;
force-reload|reload)
#TODO: actually test selenium reopens files
start-stop-daemon --stop SIGUSR1 --pidfile "${SE_PID}"
;;
*)
log_success_msg "Usage: $0 {start|stop|force-reload|restart|status|version}"
exit 1
;;
esac
exit 0
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cur_dir: "{{lookup('pipe','pwd')}}"

0 comments on commit 1d73771

Please sign in to comment.