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
45 lines
1.3 KiB
Bash
45 lines
1.3 KiB
Bash
#!/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
|
|
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 "%s $pid%s" "$cmd" "${cmdargs:+ $cmdargs}" > ${storagedir}/commands.txt || exit 1
|
|
|
|
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
|
|
}
|