Skip to content

Instantly share code, notes, and snippets.

@kimus

kimus/create-instance.sh

Last active Jan 18, 2019
Embed
What would you like to do?
Tomcat Instances and Hot Reload Nginx
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No release number version provided. Please give a release number (i.e: 1.4.9 or 1.4)"
echo "Syntax:"
echo " $0 VERSION"
exit -1
fi
REL_NAME=$1
RV=($(echo $REL_NAME | sed 's/\./\n/g'))
VER="${RV[0]}.${RV[1]}"
REV=${RV[2]}
REL_TP=snapshot
if [ -n "$REV" ]; then
REL_TP=release
REV=$(printf "%02d" $REV)
else
REV=00
fi
function release {
# random port
#REL=$(shuf -i 1000-9000 -n 1)
# fixed port using version
R=$(echo "$VER.$REV" | sed 's/\.//g')
#R=${R:1:${#R}-1}
REL=$(printf "%04d" $R)
echo "creating $REL_TP $REL_NAME ($VER rev:$REV) in port 5$REL..."
TDIR=~/tomcat7/$REL_TP/$REL_NAME
tomcat7-instance-create -p 5$REL -c 6$REL $TDIR
cat <<EOT >> $TDIR/bin/setenv.sh
# overwrite settings from default file
if [ -f "/etc/default/tomcat7" ]; then
. "/etc/default/tomcat7"
fi
EOT
mkdir -p $TDIR/conf/Catalina/localhost
cp /etc/tomcat7/Catalina/localhost/manager.xml $TDIR/conf/Catalina/localhost/
cp ~/tomcat7/default/conf/tomcat-users.xml $TDIR/conf/
cp -r ~/tomcat7/default/webapps/ROOT $TDIR/webapps/
if [ "$REL_TP" == "release" ]
then
# updates nginx: Xcur.r.domain.app + Xprv.r.domain.app
SPATH=~/tomcat7/conf
FVV=$(echo $VER | sed 's/\.//g')
CPATH=$SPATH/${FVV}cur.r.domain.app
PPATH=$SPATH/${FVV}prv.r.domain.app
# convert current to previous
cp $CPATH $PPATH
sed -i 's/cur/prv/' $CPATH
# change new current to the new port
sed -i "s/:5[0-9]*/:5$REL/" $CPATH
# reload nginx
sudo service restart reload
fi
# startup tomcat instance
/bin/bash $TDIR/bin/startup.sh
}
read -r -p "Do you wish to create $REL_TP instance for $REL_NAME ($VER rev:$REV)? [y/N] " yn
case $yn in
[Yy]) release;
;;
*) exit;;
esac
@kimus

This comment has been minimized.

Copy link
Owner Author

@kimus kimus commented Aug 29, 2016

docker create --name project-$VER.$REV \
    -v ~/tomcat7/conf/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml \
    -v ~/tomcat7/conf/manager-web.xml:/usr/local/tomcat/webapps/manager/WEB-INF/web.xml \
    -p 5$REL:8080 tomcat:7-alpine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment