From b0c2893ad78e4ad8ade3b0dd9a02196044288de8 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 20:51:47 +0000 Subject: [PATCH] Parameterize runcmd to support commands beyond storeall runcmd was hardcoded to the storeall command/status-file pair. Generalizing it now so finishcalls and dumpregistry (planned server-side additions) can reuse the same commands.txt/status..$pid polling handshake instead of needing near-duplicate copies of the function. Signature changed from `runcmd ` to `runcmd [args...]`; updated the two existing call sites (restart.sh, upgrade.sh) accordingly. Behavior for storeall itself is unchanged - verified the generated commands.txt line is byte-identical to before. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb --- restart.sh | 2 +- upgrade-funs.sh | 28 ++++++++++++++++++++++++---- upgrade.sh | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/restart.sh b/restart.sh index 454677d..4c5edad 100644 --- a/restart.sh +++ b/restart.sh @@ -8,7 +8,7 @@ fi running=$(./tomcat_ctl.sh status | grep "not running") if [ "x$running" == "x" ]; then printf "Call server command storeall.."; sleep 2 - runcmd result + runcmd result storeall if [ "x$result" == "xsuccess" ] then echo " done!" diff --git a/upgrade-funs.sh b/upgrade-funs.sh index e1bb7d2..8dfe8da 100644 --- a/upgrade-funs.sh +++ b/upgrade-funs.sh @@ -1,10 +1,30 @@ #!/bin/bash +# runcmd sends a command to the running app via the commands.txt / +# status..$pid handshake and blocks until the app reports completion. +# +# Was hardcoded to "storeall" only. Parameterized so the same function can +# drive any command that follows this same protocol - storeall today, +# finishcalls and dumpregistry once those are wired up server-side. +# +# Usage: runcmd [command args...] +# runcmd result storeall +# runcmd result finishcalls 1 +# runcmd result dumpregistry +# +# Requires $pid to already be set in the caller's scope (e.g. pid=$$), +# matching the existing convention in upgrade.sh/restart.sh. function runcmd { - local __resultvar=$1 - sfile="/home/sportrum/webapp/sportrum/WEB-INF/storage/status.storeall.$pid" + local __resultvar=$1 + local cmd=$2 + shift 2 + local cmdargs="$@" + + local storagedir="/home/sportrum/webapp/sportrum/WEB-INF/storage" + local sfile="${storagedir}/status.${cmd}.$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" + printf "%s $pid%s" "$cmd" "${cmdargs:+ $cmdargs}" > ${storagedir}/commands.txt || exit 1 + while [ ! -f $sfile ] do sleep 1 diff --git a/upgrade.sh b/upgrade.sh index 3d10c70..100538c 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -31,7 +31,7 @@ fi running=$(./tomcat_ctl.sh status | grep "tomcat8 is stopped") if [ "x$running" == "x" ]; then printf "Call server command storeall.."; sleep 2 - runcmd result + runcmd result storeall if [ "x$result" == "xsuccess" ] then echo " done!"