Skip to content

Instantly share code, notes, and snippets.

@gautamr
Created November 17, 2016 05:08
Show Gist options
  • Save gautamr/5e107ddac993b1c5d82575f5d573d476 to your computer and use it in GitHub Desktop.
Save gautamr/5e107ddac993b1c5d82575f5d573d476 to your computer and use it in GitHub Desktop.
Jenkins Tomcat shutdown/start
#!/bin/sh
CATALINA_BASE_APPS="/home/XXX/apache/tomcat-7.0.70-instance-XXX"
APP_DIST="$WORKSPACE/XXX/XXX"
APP="XXX"
PID_FILE="$CATALINA_BASE_APPS/tomcat7-XXX.pid"
if [ -f "$PID_FILE" ]
then
echo "PID file exists: $PID_FILE"
PID=$(<"$PID_FILE")
if ps -p $PID > /dev/null
then
echo "TC instance for $APP is running with PID $PID"
echo "Shutting down TC instance for $APP ..."
$CATALINA_BASE_APPS/bin/shutdown-XXX.sh
echo "Pausing for 10 seconds..."
sleep 10
if ps -p $PID > /dev/null
then
echo "No Way!!! Killing $PID with mercy ..."
kill -15 $PID
echo "Pausing for another 10 seconds ..."
sleep 10
if ps -p $PID > /dev/null
then
echo "So bad!!! You $PID must die ..."
kill -9 $PID
echo "Pausing for another 5 seconds ..."
sleep 5
fi
fi
fi
if [ -f "$PID_FILE" ]
then
echo "Deleting PID file $PID_FILE..."
rm "$PID_FILE"
fi
fi
echo "Deleting files TC files ..."
if [ -f "$CATALINA_BASE_APPS/webapps/$APP.war" ]
then
rm "$CATALINA_BASE_APPS/webapps/$APP.war"
fi
if [ -d "$CATALINA_BASE_APPS/webapps/$APP" ]
then
rm -d -r -f "$CATALINA_BASE_APPS/webapps/$APP"
fi
if [ -d "$CATALINA_BASE_APPS/logs" ]
then
rm -d -r -f "$CATALINA_BASE_APPS/logs"
fi
if [ -d "$CATALINA_BASE_APPS/logs" ]
then
rm -d -r -f "$CATALINA_BASE_APPS/logs"
fi
if [ -d "$CATALINA_BASE_APPS/temp" ]
then
rm -d -r -f "$CATALINA_BASE_APPS/temp"
fi
if [ -d "$CATALINA_BASE_APPS/work/Catalina/localhost/$APP" ]
then
rm -d -r -f "$CATALINA_BASE_APPS/work/Catalina/localhost/$APP"
fi
mkdir "$CATALINA_BASE_APPS/logs"
mkdir "$CATALINA_BASE_APPS/temp"
echo "Copying WAR file..."
cp $APP_DIST/target/$APP.war $CATALINA_BASE_APPS/webapps
echo "BUILD_ID now $BUILD_ID"
echo "Starting TC instance for $APP ..."
daemonize -E BUILD_ID=dontKillMe $CATALINA_BASE_APPS/bin/startup-XXX.sh
echo "BUILD_ID now $BUILD_ID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment