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.<cmd>.$pid polling handshake instead of needing near-duplicate copies of the function. Signature changed from `runcmd <resultvar>` to `runcmd <resultvar> <command> [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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
This commit is contained in:
parent
54bfeb73e7
commit
b0c2893ad7
3 changed files with 26 additions and 6 deletions
|
|
@ -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!"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,30 @@
|
|||
#!/bin/bash
|
||||
# runcmd sends a command to the running app via the commands.txt /
|
||||
# status.<cmd>.$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 <resultvar> <command> [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 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
|
||||
|
|
|
|||
|
|
@ -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!"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue