Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/ii-watch
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2020-02-11 13:14:20 +0100
committerErich Eckner <git@eckner.net>2020-02-11 13:14:20 +0100
commitb9a6c3c44d226ba4afaa941448b4a9b480a77505 (patch)
tree8adc32525f67732cc21e6b20f379014f66dbc2d3 /bin/ii-watch
parenta6e7e0c6e8a7b7632931dbe5dc64fbaf1c4958b6 (diff)
bin/ii-watch: check for connectivity periodically and reconnect if connection seems lost
Diffstat (limited to 'bin/ii-watch')
-rwxr-xr-xbin/ii-watch31
1 files changed, 31 insertions, 0 deletions
diff --git a/bin/ii-watch b/bin/ii-watch
index 0987656..ae1ab94 100755
--- a/bin/ii-watch
+++ b/bin/ii-watch
@@ -9,9 +9,22 @@ checksum=$(
calculate_script_checksum
)
+next_connection_check=0
+last_seen=0
+
while pgrep -x 'ii' >/dev/null && \
[ "$(calculate_script_checksum)" = "${checksum}" ]; do
# this avoids missing modifications during our last execution
+ if [ "$(date +%s)" -ge ${next_connection_check} ]; then
+ # request this more often on startup
+ if [ ${last_seen} -ne 0 ]; then
+ next_connection_check=$((
+ $(date +%s) + 60*5
+ ))
+ fi
+ echo '/NAMES #archlinux32' \
+ | sponge "${irc_dir}/in"
+ fi
if [ -z "${said}" ]; then
# shellcheck disable=SC2046
inotifywait -t 30 -e 'CLOSE_WRITE,CLOSE' -e 'CREATE,ISDIR' $(
@@ -24,4 +37,22 @@ while pgrep -x 'ii' >/dev/null && \
said=$(
"${base_dir}/bin/ii-answer"
)
+ # When was the buildmaster seen the last time?
+ last_seen=$(
+ {
+ echo 0
+ sed '
+ s/^\([0-9]\+\) = #archlinux32\( \S\+\)* buildmaster\( \S\+\)*$/\1/
+ t
+ d
+ ' "${irc_dir}/out"
+ } \
+ | sort -n \
+ | tail -n1
+ )
+ # more than 10 minutes ago
+ if [ $((last_seen + 60*10)) -lt "$(date +%s)" ]; then
+ # reconnect!
+ systemctl restart ii
+ fi
done