Created
April 29, 2016 18:03
-
-
Save rherrick/45f072514569401febfe993a29369543 to your computer and use it in GitHub Desktop.
Server reset script for the xnatdev dev/test servers
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
# Shut down Tomcat if it's running. | |
[[ $(sudo service tomcat7 status) == *running* ]] && { echo Tomcat 7 is running, shutting it down.; sudo service tomcat7 stop; } || { echo Tomcat 7 is not running.; } | |
# Sleep for a couple seconds just to make sure it's done. | |
sleep 2 | |
# Clear the database and recreate it. | |
psql -lqt | cut -d \| -f 1 | grep -qw xnatdev | |
[[ $? == 0 ]] && { echo Dropping existing database xnatdev...; dropdb xnatdev; } || { echo Database xnatdev does not exist.; } | |
echo Creating new empty database xnatdev. | |
createdb xnatdev | |
# Archive and clear the logs. | |
LOG_ARCHIVE=/var/log/tomcat7/archives/$(date +%Y%m%d%H%M%S) | |
mkdir -p ${LOG_ARCHIVE} | |
find /var/log/tomcat7 -mindepth 1 -maxdepth 1 -type f -exec mv '{}' ${LOG_ARCHIVE} \; | |
echo Archived existing logs to ${LOG_ARCHIVE}. | |
echo Removing any previous versions of the application... | |
[[ -e /usr/share/tomcat7/webapps/ROOT || -e /usr/share/tomcat7/webapps/ROOT.war ]] && { rm -rf /usr/share/tomcat7/webapps/ROOT*; } | |
echo Starting Tomcat 7... | |
sudo service tomcat7 start | |
timeout 30 sed --quiet '/INFO: Server startup in/ q' <(tail -n 0 -f catalina.out) | |
STATUS=$? | |
[[ ${STATUS} == 0 ]] && { echo Tomcat 7 was started successfully.; } || { echo Tomcat 7 does not appear to have started properly. Please check the application logs.; } | |
exit ${STATUS} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment