#!/bin/bash # LibrePlan deployment cycle script for Tomcat 9 # Usage: ./tryagain [seconds_to_wait] WAIT_SECS=${1:-15} echo "=== Cycle 1/6: Stopping Tomcat ===" sudo systemctl stop tomcat9 echo "=== Cycle 2/6: Removing old deployment ===" sudo rm -rf /opt/tomcat/webapps/libreplan* echo "=== Cycle 3/6: Deploying new WAR ===" sudo cp /space/work/pkgs/libreplan/libreplan-webapp/target/libreplan-webapp.war /opt/tomcat/webapps/libreplan.war echo "=== Cycle 4/6: Clearing old logs ===" sudo truncate -s 0 /opt/tomcat/logs/catalina.out sudo rm -f /opt/tomcat/logs/localhost.*.log echo "=== Cycle 5/6: Starting Tomcat ===" sudo systemctl start tomcat9 echo "=== Cycle 6/6: Waiting ${WAIT_SECS}s for deployment ===" for i in $(seq 1 $WAIT_SECS); do echo -ne "\r $i / $WAIT_SECS seconds..." sleep 1 done echo "" echo "=== Copying logs ===" sudo cp /opt/tomcat/logs/catalina.out /space/work/pkgs/libreplan/migrate/catalina.out sudo chmod 644 /space/work/pkgs/libreplan/migrate/catalina.out LOCALHOST_LOG=$(ls -t /opt/tomcat/logs/localhost.*.log 2>/dev/null | head -1) if [ -n "$LOCALHOST_LOG" ]; then sudo cp "$LOCALHOST_LOG" /space/work/pkgs/libreplan/migrate/localhost.log sudo chmod 644 /space/work/pkgs/libreplan/migrate/localhost.log fi echo "" echo "=== Result ===" if grep -q "Server startup in" /space/work/pkgs/libreplan/migrate/catalina.out; then echo "SUCCESS: Tomcat started" grep "Server startup in" /space/work/pkgs/libreplan/migrate/catalina.out elif grep -q "startup failed" /space/work/pkgs/libreplan/migrate/catalina.out; then echo "FAILED: Deployment failed" grep -i "exception\|error\|caused by" /space/work/pkgs/libreplan/migrate/localhost.log 2>/dev/null | head -5 else echo "IN PROGRESS: Still deploying..." tail -3 /space/work/pkgs/libreplan/migrate/catalina.out fi