#!/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 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 } # maintenance_log drops one XML file per event into the maintenance-log # folder for the sportrum webapp to pick up, deserialize into a # MaintenanceLog object, and act on (trigger sms/email/etc through its # own machinery - see MaintenanceLog.java). Fire-and-forget: this # function doesn't wait for anything to process the file, and there's no # execution-status handshake back to the caller - it just needs to land a # well-formed file. # # Usage: maintenance_log [extra_xml] # maintenance_log info nightly_storeall storeall quiet "storeall completed." # # severity/operation/action/reason are free-form lowercase tokens (e.g. # severity: info|warning|error, action: nop|storeall, reason: # busy|quiet|no_quiet_window) - adjust the exact vocabulary to match # whatever the webapp's Severity/MaintenanceType lookups actually expect. # # , if given, is inserted verbatim as additional children # inside
(e.g. "42") - caller is # responsible for passing well-formed XML there. # # Written via a temp file + atomic rename so whatever's watching the # directory never sees a partially-written file. function maintenance_log { local severity=$1 local operation=$2 local action=$3 local reason=$4 local message=$5 local extra_xml="${6:-}" local logdir="/home/sportrum/webapp/sportrum/WEB-INF/storage/maintenance-log" mkdir -p "$logdir" local esc_message esc_message=$(printf '%s' "$message" | sed -e 's/&/\&/g; s//\>/g') local ts_utc ts_utc="$(date -u +%Y-%m-%dT%H:%M:%SZ)" local fname fname="$(date -u +%Y%m%dT%H%M%S).$$.${severity}" local tmpfile="${logdir}/.${fname}.tmp" local finalfile="${logdir}/${fname}.xml" cat > "$tmpfile" < ${ts_utc} ${severity} ${operation} ${action} ${reason}
$(hostname) ${esc_message} ${extra_xml}
EOF mv "$tmpfile" "$finalfile" }