Import existing manual deploy scripts as a starting point
These are the scripts currently run by hand on the old EC2 server to do a full upgrade (safe storeall handshake, backups, explode WAR, run the manager schema-migration tool, restart Tomcat). Committed as-is for now to review and refactor from, except tomcat_ctl.sh, which is already rewritten to control Tomcat via the new Docker container's supervisord (through the "service" shim) instead of the old host's /etc/init.d/tomcat8, since that service doesn't exist there. Kept as a drop-in replacement: the "status" output still contains both literal substrings upgrade.sh and restart.sh each grep for, so neither caller needed to change yet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
This commit is contained in:
commit
54bfeb73e7
6 changed files with 196 additions and 0 deletions
12
.gitattributes
vendored
Normal file
12
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
# Force LF line endings for these shell scripts regardless of what a
|
||||||
|
# checkout client's own core.autocrlf setting would otherwise do.
|
||||||
|
#
|
||||||
|
# Without this, a checkout on Windows (e.g. via Git for Windows/SourceTree
|
||||||
|
# with the common core.autocrlf=true default) can silently convert these to
|
||||||
|
# CRLF. A CRLF shell script still LOOKS fine and even shows as executable —
|
||||||
|
# but its shebang line becomes "#!/bin/bash\r", which the kernel reads
|
||||||
|
# literally, looking for an interpreter named "bash\r" that doesn't exist.
|
||||||
|
# We already hit exactly this failure mode once this session on
|
||||||
|
# xzpect-timer's deploy-pwa.sh ("env: $'bash\r': No such file or directory",
|
||||||
|
# exit 127) — same fix here, applied up front this time.
|
||||||
|
*.sh text eol=lf
|
||||||
28
restart.sh
Normal file
28
restart.sh
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash
|
||||||
|
. ./upgrade-funs.sh
|
||||||
|
action="reboot"
|
||||||
|
pid=$$
|
||||||
|
if [ "x$1" != "x" ]; then
|
||||||
|
action=$1;
|
||||||
|
fi
|
||||||
|
running=$(./tomcat_ctl.sh status | grep "not running")
|
||||||
|
if [ "x$running" == "x" ]; then
|
||||||
|
printf "Call server command storeall.."; sleep 2
|
||||||
|
runcmd result
|
||||||
|
if [ "x$result" == "xsuccess" ]
|
||||||
|
then
|
||||||
|
echo " done!"
|
||||||
|
else
|
||||||
|
echo " failed! exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Stopping tomcat.."; sleep 2
|
||||||
|
./tomcat_ctl.sh stop
|
||||||
|
else
|
||||||
|
echo "Tomcat is not running!"
|
||||||
|
fi
|
||||||
|
if [ $action == "reboot" ]; then
|
||||||
|
echo "Starting tomcat..."; sleep 2
|
||||||
|
./tomcat_ctl.sh start
|
||||||
|
fi
|
||||||
|
|
||||||
41
tomcat_ctl.sh
Normal file
41
tomcat_ctl.sh
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Rewritten for the new Docker-based server: Tomcat runs under supervisord
|
||||||
|
# inside the app container, not as a real /etc/init.d/tomcat8 service like on
|
||||||
|
# the old EC2 host. start/stop/restart go through the "service" shim the
|
||||||
|
# Dockerfile installs (sportrum-ansible's files/app/service-shim.sh), already
|
||||||
|
# proven working this session (`sudo service tomcat restart` -> "tomcat:
|
||||||
|
# stopped" / "tomcat: started"). status queries supervisorctl directly
|
||||||
|
# instead, since its output format is well-defined and doesn't depend on
|
||||||
|
# what commands the shim itself happens to support.
|
||||||
|
#
|
||||||
|
# Kept as a drop-in replacement on purpose: upgrade.sh and restart.sh each
|
||||||
|
# grep this script's "status" output for a different literal string
|
||||||
|
# ("tomcat8 is stopped" vs "not running") depending on which one calls it.
|
||||||
|
# Both substrings are included below whenever tomcat isn't running, so
|
||||||
|
# neither caller needs to change.
|
||||||
|
#
|
||||||
|
# JAVA_HOME/JAVA_OPTS from the old version are dropped: the container's base
|
||||||
|
# image (eclipse-temurin) already sets JAVA_HOME itself, and the JAVA_OPTS
|
||||||
|
# line here was commented out (inactive) in the original anyway. If real
|
||||||
|
# JAVA_OPTS are ever needed, set them in the container's own environment
|
||||||
|
# (docker-compose.yml.j2's "environment:" block for the app service) rather
|
||||||
|
# than here.
|
||||||
|
cmd=$1
|
||||||
|
|
||||||
|
case "$cmd" in
|
||||||
|
status)
|
||||||
|
raw=$(sudo supervisorctl status tomcat)
|
||||||
|
if echo "$raw" | grep -q "RUNNING"; then
|
||||||
|
echo "tomcat8 is running: $raw"
|
||||||
|
else
|
||||||
|
echo "tomcat8 is stopped, not running: $raw"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
start|stop|restart)
|
||||||
|
sudo service tomcat "$cmd"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown command: $cmd" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
33
upgrade-cmds.sh
Normal file
33
upgrade-cmds.sh
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
backupdir="/home/sportrum/backup"
|
||||||
|
timestamp=$(date +'%Y%m%d-%H%M%S')
|
||||||
|
sqlbackup="sportrum-upgrade-backup-${timestamp}.sqldump"
|
||||||
|
webappbackup="sportrum-upgrade-backup-${timestamp}.war"
|
||||||
|
logsbackup="sportrum-log-backup-${timestamp}"
|
||||||
|
if [ "$backup_sql" == "true" ]; then
|
||||||
|
echo "Backup database to ${sqlbackup}..."; sleep 2
|
||||||
|
pg_dump sportrum > ${backupdir}/sql/${sqlbackup}
|
||||||
|
else
|
||||||
|
echo "Backup of database skipped!"
|
||||||
|
fi
|
||||||
|
if [ "$backup_war" == "true" ]; then
|
||||||
|
echo "Backup webapp to ${webappbackup}..."; sleep 2
|
||||||
|
cd /home/sportrum/webapp
|
||||||
|
zip -q -r sportrum sportrum
|
||||||
|
mv sportrum.zip ${backupdir}/webapp/${webappbackup}
|
||||||
|
else
|
||||||
|
echo "Backup webapp skipped!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd /home/sportrum/webapp
|
||||||
|
echo "Keep logs in ${backupdir}/logs/${logbackup}..."; sleep 1
|
||||||
|
mkdir -p ${backupdir}/logs/${logsbackup}
|
||||||
|
cp sportrum/logs/* ${backupdir}/logs/${logsbackup}
|
||||||
|
|
||||||
|
echo "Remove webapp at $(pwd) and unzip new war..."; sleep 2
|
||||||
|
rm -rf sportrum/* ; unzip -q sportrum.war -d sportrum
|
||||||
|
chmod -R o+w sportrum/WEB-INF/storage
|
||||||
|
chmod -R o+w sportrum/logs
|
||||||
|
cd /home/sportrum/
|
||||||
|
echo "Upgrade DB using manager at $(pwd)/manager..."; sleep 2
|
||||||
|
rm -rf manager ; unzip -q manager.zip ; cd manager
|
||||||
|
bash -x manager-exec.sh upgrade
|
||||||
25
upgrade-funs.sh
Normal file
25
upgrade-funs.sh
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/bash
|
||||||
|
function runcmd {
|
||||||
|
local __resultvar=$1
|
||||||
|
sfile="/home/sportrum/webapp/sportrum/WEB-INF/storage/status.storeall.$pid"
|
||||||
|
rm -f ${sfile}
|
||||||
|
printf "storeall $pid" > /home/sportrum/webapp/sportrum/WEB-INF/storage/commands.txt || exit 1
|
||||||
|
sfile="/home/sportrum/webapp/sportrum/WEB-INF/storage/status.storeall.$pid"
|
||||||
|
while [ ! -f $sfile ]
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
status=$(cut -d " " -f 1 $sfile)
|
||||||
|
if [ "x$(echo $status | cut -d ':' -f 1)" == "xcompleted" ]
|
||||||
|
then
|
||||||
|
local funresult="$(echo $status | cut -d ':' -f 2)"
|
||||||
|
eval $__resultvar="'$funresult'"
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
echo "$(cat $sfile)"
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
57
upgrade.sh
Normal file
57
upgrade.sh
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/bin/bash
|
||||||
|
. ./upgrade-funs.sh
|
||||||
|
action="reboot"
|
||||||
|
pid=$$
|
||||||
|
backup_sql="true"
|
||||||
|
backup_war="true"
|
||||||
|
storeonly="false"
|
||||||
|
while getopts "fsw" option
|
||||||
|
do
|
||||||
|
case $option in
|
||||||
|
f)
|
||||||
|
backup_sql="false"
|
||||||
|
backup_war="false"
|
||||||
|
;;
|
||||||
|
w)
|
||||||
|
backup_sql="false"
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
storeonly="true"
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $(($OPTIND - 1))
|
||||||
|
if [ "x$1" != "x" ]; then
|
||||||
|
action=$1;
|
||||||
|
fi
|
||||||
|
running=$(./tomcat_ctl.sh status | grep "tomcat8 is stopped")
|
||||||
|
if [ "x$running" == "x" ]; then
|
||||||
|
printf "Call server command storeall.."; sleep 2
|
||||||
|
runcmd result
|
||||||
|
if [ "x$result" == "xsuccess" ]
|
||||||
|
then
|
||||||
|
echo " done!"
|
||||||
|
else
|
||||||
|
echo " failed! exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Stopping tomcat.."; sleep 2
|
||||||
|
./tomcat_ctl.sh stop
|
||||||
|
else
|
||||||
|
echo "Tomcat is not running!"
|
||||||
|
fi
|
||||||
|
if [ $storeonly != "true" ]; then
|
||||||
|
runcmds=$(cat upgrade-cmds.sh)
|
||||||
|
sudo su - sportrum -c "backup_sql=$backup_sql; backup_war=$backup_war; ${runcmds}"
|
||||||
|
else
|
||||||
|
echo "Skipping upgrade commands, store only mode"
|
||||||
|
fi
|
||||||
|
if [ $action == "reboot" ]; then
|
||||||
|
echo "Starting tomcat..."; sleep 2
|
||||||
|
./tomcat_ctl.sh start
|
||||||
|
fi
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue