Skip to content

Commit

Permalink
Initial commit of a simple jboss standalone application server deploy…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
tgerla committed Jun 26, 2013
1 parent 4056f51 commit 0fee3d7
Show file tree
Hide file tree
Showing 9 changed files with 592 additions and 0 deletions.
31 changes: 31 additions & 0 deletions jboss-standalone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Standalone JBoss Deployment

- Requires Ansible 1.2 or newer
- Expects CentOS/RHEL 6.x hosts

These playbooks deploy a very basic implementation of JBoss Application Server,
version 7. To use them, first edit the "hosts" inventory file to contain the
hostnames of the machines on which you want JBoss deployed, and edit the
group_vars/jboss-servers file to set any JBoss configuration parameters you need.

Then run the playbook, like this:

ansible-playbook -i hosts site.yml

When the playbook run completes, you should be able to see the JBoss
Application Server running on the ports you chose, on the target machines.

This is a very simple playbook and could serve as a starting point for more
complex JBoss-based projects.

### Ideas for Improvement

Here are some ideas for ways that these playbooks could be extended:

- Write a playbook or an Ansible module to configure JBoss users.
- Write a playbook to deploy an actual application into the server.
- Extend this configuration to multiple application servers fronted by a load
balancer or other web server frontend.

We would love to see contributions and improvements, so please fork this
repository on GitHub and send us your changes via pull requests.
4 changes: 4 additions & 0 deletions jboss-standalone/group_vars/jboss-servers
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Here are variables related to the standalone JBoss installation

http_port: 8080
https_port: 8443
2 changes: 2 additions & 0 deletions jboss-standalone/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[jboss-servers]
webserver1
180 changes: 180 additions & 0 deletions jboss-standalone/roles/jboss-standalone/files/jboss-as-standalone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#!/bin/sh
#
# JBoss standalone control script
#
# chkconfig: - 80 20
# description: JBoss AS Standalone
# processname: standalone
# pidfile: /var/run/jboss-as/jboss-as-standalone.pid
# config: /etc/jboss-as/jboss-as.conf

# Source function library.
. /etc/init.d/functions

# Load Java configuration.
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME

##
# Set the JBoss user
JBOSS_USER=jboss
export JBOSS_USER

# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
fi

[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"

# Set defaults.

if [ -z "$JBOSS_HOME" ]; then
JBOSS_HOME=/usr/share/jboss-as
fi
export JBOSS_HOME

if [ -z "$JBOSS_PIDFILE" ]; then
JBOSS_PIDFILE=/var/run/jboss-as/jboss-as-standalone.pid
fi
export JBOSS_PIDFILE

if [ -z "$JBOSS_CONSOLE_LOG" ]; then
JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log
fi

if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=30
fi

if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi

if [ -z "$JBOSS_CONFIG" ]; then
JBOSS_CONFIG=standalone.xml
fi

JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.sh

prog='jboss-as'

CMD_PREFIX=''

if [ ! -z "$JBOSS_USER" ]; then
if [ -x /etc/rc.d/init.d/functions ]; then
CMD_PREFIX="daemon --user $JBOSS_USER"
else
CMD_PREFIX="su - $JBOSS_USER -c"
fi
fi

start() {
echo -n "Starting $prog: "
if [ -f $JBOSS_PIDFILE ]; then
read ppid < $JBOSS_PIDFILE
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo -n "$prog is already running"
failure
echo
return 1
else
rm -f $JBOSS_PIDFILE
fi
fi
mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
cat /dev/null > $JBOSS_CONSOLE_LOG

mkdir -p $(dirname $JBOSS_PIDFILE)
chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT 2>&1 > $JBOSS_CONSOLE_LOG &
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT &

if [ ! -z "$JBOSS_USER" ]; then
if [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &
else
su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &
fi
fi

count=0
launched=false

until [ $count -gt $STARTUP_WAIT ]
do
grep 'JBoss AS.*started in' $JBOSS_CONSOLE_LOG > /dev/null
if [ $? -eq 0 ] ; then
launched=true
break
fi
sleep 1
let count=$count+1;
done

success
echo
return 0
}

stop() {
echo -n $"Stopping $prog: "
count=0;

if [ -f $JBOSS_PIDFILE ]; then
read kpid < $JBOSS_PIDFILE
let kwait=$SHUTDOWN_WAIT

# Try issuing SIGTERM

kill -15 $kpid
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
sleep 1
let count=$count+1;
done

if [ $count -gt $kwait ]; then
kill -9 $kpid
fi
fi
rm -f $JBOSS_PIDFILE
success
echo
}

status() {
if [ -f $JBOSS_PIDFILE ]; then
read ppid < $JBOSS_PIDFILE
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo "$prog is running (pid $ppid)"
return 0
else
echo "$prog dead but pid file exists"
return 1
fi
fi
echo "$prog is not running"
return 3
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
status)
status
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|status|restart|reload}"
exit 1
;;
esac
6 changes: 6 additions & 0 deletions jboss-standalone/roles/jboss-standalone/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: restart jboss
service: name=jboss state=restarted

- name: restart iptables
service: name=iptables state=restarted
39 changes: 39 additions & 0 deletions jboss-standalone/roles/jboss-standalone/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: Install Java 1.7 and some basic dependencies
yum: name={{item}} state=present
with_items:
- unzip
- java-1.7.0-openjdk

- name: Download JBoss from jboss.org
get_url: url=http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip dest=/opt/jboss-as-7.1.1.Final.zip

- name: Extract archive
command: chdir=/usr/share /usr/bin/unzip -q /opt/jboss-as-7.1.1.Final.zip creates=/usr/share/jboss-as

# Rename the dir to avoid encoding the version in the init script
- name: Rename install directory
command: chdir=/usr/share /bin/mv jboss-as-7.1.1.Final jboss-as creates=/usr/share/jboss-as

- name: Copying standalone.xml configuration file
template: src=standalone.xml dest=/usr/share/jboss-as/standalone/configuration/
notify: restart jboss

- name: Add group "jboss"
group: name=jboss

- name: Add user "jboss"
user: name=jboss group=jboss home=/usr/share/jboss-as

- name: Change ownership of JBoss installation
file: path=/usr/share/jboss-as/ owner=jboss group=jboss state=directory recurse=yes

- name: Copy the init script
copy: src=jboss-as-standalone.sh dest=/etc/init.d/jboss mode=0755

- name: Enable JBoss to be started at boot
service: name=jboss enabled=yes state=started

- name: deploy iptables rules
template: src=iptables-save dest=/etc/sysconfig/iptables
notify: restart iptables
14 changes: 14 additions & 0 deletions jboss-standalone/roles/jboss-standalone/templates/iptables-save
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# {{ ansible_managed }}
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:512]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport {{ http_port }} -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport {{ https_port }} -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Loading

0 comments on commit 0fee3d7

Please sign in to comment.