Last active
January 18, 2019 19:10
-
-
Save kimus/ea90f5a6dbb0a17101cfab65f5fb1ace to your computer and use it in GitHub Desktop.
Tomcat Instances and Hot Reload Nginx
This file contains 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
#!/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 |
Author
kimus
commented
Aug 29, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment