summaryrefslogtreecommitdiffstats
path: root/core/modules/hardware-stats/data
diff options
context:
space:
mode:
authorSimon Rettberg2023-02-15 11:50:16 +0100
committerSimon Rettberg2023-02-15 11:50:16 +0100
commitdf8870cc20afdeed1fe472fe8fa433c113f8e1bf (patch)
tree0d8577fd1524e235f6cd7088f5c57462a7991851 /core/modules/hardware-stats/data
parent[run-virt] Don't slxlog, include curl log in main log instead, increase timeout (diff)
downloadmltk-df8870cc20afdeed1fe472fe8fa433c113f8e1bf.tar.gz
mltk-df8870cc20afdeed1fe472fe8fa433c113f8e1bf.tar.xz
mltk-df8870cc20afdeed1fe472fe8fa433c113f8e1bf.zip
[remote-access/hardware-stats] Try harder to avoid races and keep order
Don't send usage updates or the VNC password before we haven't successfully sent the ~poweron event.
Diffstat (limited to 'core/modules/hardware-stats/data')
-rwxr-xr-xcore/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update19
-rwxr-xr-xcore/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report12
2 files changed, 19 insertions, 12 deletions
diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update b/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update
index 832f2078..c3638006 100755
--- a/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update
+++ b/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update
@@ -97,15 +97,18 @@ if $full; then
fi
# Bail out if we already sent the shutdown event to server
+# or if the cron-job hasn't been set up yet.
# Do this right before the curl call to minimize odds for a race condition
-[ -e /run/openslx/shutdown.mutex ] && exit 0
-curl --retry 3 --retry-connrefused -m 6 -s --data-urlencode "type=~runstate" --data-urlencode "uuid=$UUID" --data-urlencode "used=$USED" \
- --data-urlencode "user=$Name" --data-urlencode "tmpsize=$TMP_SIZE" --data-urlencode "tmpfree=$TMP_FREE" \
- --data-urlencode "id45size=$ID45_SIZE" --data-urlencode "id45free=$ID45_FREE" \
- --data-urlencode "swapsize=$SWAP_SIZE" --data-urlencode "swapfree=$SWAP_FREE" \
- --data-urlencode "memsize=$MEM_SIZE" --data-urlencode "memfree=$MEM_FREE" \
- "$@" \
- "$SLX_REMOTE_LOG" > /dev/null 2>&1
+if [ -e "/etc/cron.d/usage_stats" ] && ! [ -e "/run/openslx/shutdown.mutex" ]; then
+ curl --retry 3 --retry-connrefused -m 6 -s --data-urlencode "type=~runstate" --data-urlencode "uuid=$UUID" \
+ --data-urlencode "used=$USED" \
+ --data-urlencode "user=$Name" --data-urlencode "tmpsize=$TMP_SIZE" --data-urlencode "tmpfree=$TMP_FREE" \
+ --data-urlencode "id45size=$ID45_SIZE" --data-urlencode "id45free=$ID45_FREE" \
+ --data-urlencode "swapsize=$SWAP_SIZE" --data-urlencode "swapfree=$SWAP_FREE" \
+ --data-urlencode "memsize=$MEM_SIZE" --data-urlencode "memfree=$MEM_FREE" \
+ "$@" \
+ "$SLX_REMOTE_LOG" > /dev/null 2>&1
+fi
# Warn user if tmp or swap usage is high; system might crash soon
diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report
index b162b8a8..5a93742e 100755
--- a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report
+++ b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_report
@@ -62,12 +62,15 @@ report_hardware_info() {
# got everything, get the last infos
uptime=$(grep -oE '^[0-9]+' /proc/uptime)
echo -n "Submitting to '$SLX_REMOTE_LOG' ... "
- curl --retry 4 --retry-connrefused --max-time 5 --retry-max-time 15 \
+ curl --retry 4 --retry-connrefused --max-time 8 --retry-max-time 15 \
--data-urlencode "type=~poweron" --data-urlencode "uuid=$uuid" --data-urlencode "macaddr=$HW_MAC" \
- --data-urlencode "uptime=$uptime" --data-urlencode "realcores=$HW_CORES" --data-urlencode "vcores=$HW_THREADS" \
+ --data-urlencode "uptime=$uptime" --data-urlencode "realcores=$HW_CORES" \
+ --data-urlencode "vcores=$HW_THREADS" \
--data-urlencode "sockets=$HW_SOCKETS" --data-urlencode "mbram=$HW_MBRAM" \
- --data-urlencode "kvmstate=$HW_KVM" --data-urlencode "cpumodel=$HW_CPUMODEL" --data-urlencode "id44mb=$HW_ID44" \
- --data-urlencode "badsectors=$HW_BADSECTORS" --data-urlencode "systemmodel=$model" --data-urlencode "subnet=$subnet" \
+ --data-urlencode "kvmstate=$HW_KVM" --data-urlencode "cpumodel=$HW_CPUMODEL" \
+ --data-urlencode "id44mb=$HW_ID44" \
+ --data-urlencode "badsectors=$HW_BADSECTORS" --data-urlencode "systemmodel=$model" \
+ --data-urlencode "subnet=$subnet" \
--data-urlencode "runmode=$runmode" --data-urlencode "data@$hwreport" --data-urlencode "json@$jsonfile" \
"$SLX_REMOTE_LOG" | grep -q "RESULT=0"
local ret=$?
@@ -80,6 +83,7 @@ report_hardware_info() {
rm -f -- "$hwreport" "$jsonfile"
START=$(( $RANDOM % 5 ))
DELAY=$(( $RANDOM % 20 ))
+ # Do not move/rename this file, we check its existence in other scripts
cat > "/etc/cron.d/usage_stats" <<-EOF
# Update usage statistics on server
SHELL=/bin/sh