Created
September 6, 2013 12:49
-
-
Save robmazan/6463335 to your computer and use it in GitHub Desktop.
Vagrant tc Server provisioning
This file contains hidden or 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
#!/usr/bin/env bash | |
function setJavaHome { | |
if grep -q "JAVA_HOME" /etc/environment; then | |
echo "JAVA_HOME already set..." | |
else | |
echo "Setting JAVA_HOME..." | |
echo "JAVA_HOME=$1" >> /etc/environment | |
fi | |
} | |
function setTcUsers { | |
local USERS_FILE="$1/conf/tomcat-users.xml" | |
if grep -q '<user .* roles="manager-gui"' $USERS_FILE; then | |
echo "Tomcat admin user already set..." | |
else | |
echo "Setting Tomcat admin user..." | |
local ADMIN_USER="admin" | |
local ADMIN_PASSWORD="xxxx1111" | |
read -d '' TOMCAT_USERS << EOF | |
<?xml version="1.0"?> | |
<tomcat-users> | |
<role rolename="manager-gui" /> | |
<user username="$ADMIN_USER" password="$ADMIN_PASSWORD" roles="manager-gui" /> | |
</tomcat-users> | |
EOF | |
echo "$TOMCAT_USERS" > "$USERS_FILE" | |
fi | |
} | |
function configureServer { | |
local CONFIG_FILE="$1/conf/context.xml" | |
if grep -q '<Resource name="jdbc/DSRediscover"' $CONFIG_FILE; then | |
echo "Server already configured..." | |
else | |
echo "Configuring server..." | |
local HOST_IP=`route -n | awk '/0.0.0.0/ {print $2; exit;}'` | |
read -d '' RESOURCE_CONFIG << EOF | |
<Resource name="jdbc/DSRediscover" auth="Container" type="javax.sql.DataSource" | |
username="SPRITE" password="Sprite123" driverClassName="oracle.jdbc.OracleDriver" | |
url="jdbc:oracle:thin:@$HOST_IP:1521:orcl" /> | |
<Resource name="mail/default_jms" auth="Container" type="javax.mail.Session" | |
mail.debug="false" | |
mail.transport.protocol="smtp" | |
mail.smtp.host="$HOST_IP" | |
mail.smtp.auth="false" | |
mail.smtp.port="25" | |
mail.smtp.starttls.enable="false" | |
description="Global E-Mail Resource" /> | |
EOF | |
local CONFIG=$(awk -v RESCFG="$RESOURCE_CONFIG" ' | |
/<\/Context>/ { print RESCFG } | |
{print $0} | |
' "$CONFIG_FILE") | |
echo "$CONFIG" > "$CONFIG_FILE" | |
fi | |
} | |
function configureTcEnv { | |
local CONFIG_FILE="$1/bin/setenv.sh" | |
if grep -q '^JAVA_OPTS=.*-Duser.timezone=' $CONFIG_FILE; then | |
echo "Server environment already configured..." | |
else | |
echo "Configuring server environment..." | |
local NEW_OPTS="-Duser.timezone=UTC -Denvironment=dev -Dnode_id=tcserver -Dinsight.enabled=true " | |
local CONFIG=$(awk -v OPTS="$NEW_OPTS" ' | |
/^JAVA_OPTS=/ { $0="JAVA_OPTS=\"" OPTS substr($0, 12)} | |
{print $0} | |
' "$CONFIG_FILE") | |
echo "$CONFIG" > "$CONFIG_FILE" | |
fi | |
} | |
function downloadLibs { | |
local LIB_DIR="$1/lib" | |
echo "Checking required Java libs..." | |
pushd "$LIB_DIR" > /dev/null | |
wget -q -nc http://repo1.maven.org/maven2/javax/mail/mail/1.4.6/mail-1.4.6.jar | |
cp -n /vagrant/lib/* . | |
popd > /dev/null | |
} | |
function copyWAR { | |
local WEBAPPS_DIR="$1/webapps" | |
local WAR_PATH=`find /vagrant/target/ -iname *.war` | |
if [ -f "$WAR_PATH" ]; then | |
echo "Updating webapp..." | |
cp -f "$WAR_PATH" "$WEBAPPS_DIR/rediscover.war" | |
else | |
echo "No webapp found in target directory!" | |
fi | |
} | |
function configureInstance { | |
local BASE_DIR="$1" | |
echo "Configuring instance $BASE_DIR..." | |
setTcUsers "$BASE_DIR" | |
configureServer "$BASE_DIR" | |
configureTcEnv "$BASE_DIR" | |
downloadLibs "$BASE_DIR" | |
copyWAR "$BASE_DIR" | |
} | |
function installTcServer { | |
local TCSERVER_NAME="$1" | |
local TCSERVER_ARCHIVE="$TCSERVER_NAME.tar.gz" | |
local INSTANCE_NAME="tccc-sp13-server" | |
if [ -d "/opt/vmware/$TCSERVER_NAME" ]; then | |
echo "The tc Server is already installed..." | |
else | |
echo "Creating groups and users for tc Server..." | |
groupadd spring | |
useradd hyperic -g spring | |
useradd tcserver -g spring | |
echo "Downloading tc Server..." | |
wget -q -nc https://dl.dropboxusercontent.com/u/62555201/tmp/$TCSERVER_ARCHIVE | |
echo "Uncompressing tc Server archive..." | |
mkdir /opt/vmware | |
tar -xvzf $TCSERVER_ARCHIVE -C /opt/vmware | |
chown -R tcserver:spring /opt/vmware | |
fi | |
cd /opt/vmware/$TCSERVER_NAME | |
if [ -d "/opt/vmware/$TCSERVER_NAME/$INSTANCE_NAME" ]; then | |
echo "Instance '$INSTANCE_NAME' already exists..." | |
else | |
echo "Preparing tc Server instance '$INSTANCE_NAME'..." | |
su tcserver -c "./tcruntime-instance.sh create -t bio-ssl -t insight $INSTANCE_NAME" | |
fi | |
configureInstance "tccc-sp13-server" | |
} | |
update-locale LC_ALL=en_US.UTF8 | |
echo "Installing/updating packages..." | |
apt-get -qq update | |
apt-get -qq -y install mc | |
apt-get -qq -y install ttf-dejavu | |
apt-get -qq -y install openjdk-6-jre-headless | |
setJavaHome "/usr/lib/jvm/java-6-openjdk-amd64" | |
installTcServer "vfabric-tc-server-developer-2.9.3.RELEASE" | |
echo "Starting tc Server instance..." | |
su tcserver -c "./tcruntime-ctl.sh tccc-sp13-server start" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment