From 2c927a2e8032ea992605a38caedfdc4996414f1a Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 28 Jun 2024 14:04:57 -0400 Subject: [PATCH] Added vm host watcher --- dmoj/scripts/vm-host-problem-watch | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 dmoj/scripts/vm-host-problem-watch diff --git a/dmoj/scripts/vm-host-problem-watch b/dmoj/scripts/vm-host-problem-watch new file mode 100644 index 0000000..91c0f78 --- /dev/null +++ b/dmoj/scripts/vm-host-problem-watch @@ -0,0 +1,23 @@ +#!/bin/bash + +problem_storage_root="$(realpath "$1")" +judge_hosts_file="$(realpath "$2")" + +cd $(dirname $0) || exit + +. ./scripts/utils/notify + +echo "$(date): Start watching ${problem_storage_root}, notifying ${judge_hosts_file}" + +inotifywait -rm "${problem_storage_root}" -e move,create,delete -q | while read -r line; do + if [ "$(echo "$line" | cut -d' ' -f3)" != "init.yml" ]; then + continue + fi + + notify "Judge problems updated" + echo "$(date): Update problems [$line]" + readarray -t judges < "${judge_hosts_file}" + for judge in "${judges[@]}"; do + curl -4 -s -X POST "http://$judge/update/problems" | sed "s/^/$(date) [$judge]: /"';$a\' + done +done