sportrum-deploy/upgrade-funs.sh

46 lines
1.3 KiB
Bash
Raw Normal View History

#!/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
}