From c97873d2cf2b1bfd86d3ab1c9701471427a008a4 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 13 Jun 2023 15:30:31 +0200 Subject: [PATCH 1/2] pdist: Add pdistd service for distmaster(s) To implement auto-update on boot, we need a way for a client to trigger a pdist-update for itself on its distmaster. Add a service for the distmaster(s), which allows a client to do that by connecting to a fixed port on the distmaster (`telnet deinemuddah 237`). --- install.sh | 2 ++ pdist/pdistd.socket | 10 ++++++++++ pdist/pdistd@.service | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 pdist/pdistd.socket create mode 100644 pdist/pdistd@.service diff --git a/install.sh b/install.sh index 650a91dd..ba83afba 100755 --- a/install.sh +++ b/install.sh @@ -273,6 +273,8 @@ install_exec mxstartup/mxstartupctl "$DESTDIR$usr_sbindir/ install_exec mxstartup/mxvipctl "$DESTDIR$usr_sbindir/mxvipctl" install_data mxstartup/mxstartup.service "$DESTDIR$systemdunitdir/mxstartup.service" install_data misc_systemd_units/lightdm.service "$DESTDIR$systemdunitdir/lightdm.service" +install_data pdist/pdistd.socket "$DESTDIR$systemdunitdir/pdistd.socket" +install_data pdist/pdistd@.service "$DESTDIR$systemdunitdir/pdistd@.service" postinstall exit diff --git a/pdist/pdistd.socket b/pdist/pdistd.socket new file mode 100644 index 00000000..786ce87a --- /dev/null +++ b/pdist/pdistd.socket @@ -0,0 +1,10 @@ +[Unit] +ConditionPathExists=/node/tags/distmaster + +[Socket] +ListenStream=237 +ReusePort=yes +Accept=yes + +[Install] +WantedBy=multi-user.target diff --git a/pdist/pdistd@.service b/pdist/pdistd@.service new file mode 100644 index 00000000..5f5636b6 --- /dev/null +++ b/pdist/pdistd@.service @@ -0,0 +1,6 @@ +[Unit] +CollectMode=inactive-or-failed + +[Service] +StandardOutput=socket +ExecStart=bash -c "read ip host <<< $(getent hosts ${REMOTE_ADDR}) ; echo update in progess... ; pdist push $host --timeout 60 --set-pdist-status" From 5e1364482479f323e0a11124c0dc6697959f74e3 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Wed, 14 Jun 2023 16:35:01 +0200 Subject: [PATCH 2/2] pdist: Add pdist-bootcheck Add service to check pdist time for the booting system. If older than 7 days, request a synchonous pdist from the distmater and reboot. If only older than 1 day, require an asynchronous pdist while the boot can continue. --- install.sh | 2 ++ pdist/pdist-bootcheck | 42 +++++++++++++++++++++++++++++++++++ pdist/pdist-bootcheck.service | 15 +++++++++++++ 3 files changed, 59 insertions(+) create mode 100755 pdist/pdist-bootcheck create mode 100644 pdist/pdist-bootcheck.service diff --git a/install.sh b/install.sh index ba83afba..e1c66a15 100755 --- a/install.sh +++ b/install.sh @@ -275,6 +275,8 @@ install_data mxstartup/mxstartup.service "$DESTDIR$systemdunitd install_data misc_systemd_units/lightdm.service "$DESTDIR$systemdunitdir/lightdm.service" install_data pdist/pdistd.socket "$DESTDIR$systemdunitdir/pdistd.socket" install_data pdist/pdistd@.service "$DESTDIR$systemdunitdir/pdistd@.service" +install_exec pdist/pdist-bootcheck "$DESTDIR$usr_exec_prefix/libexec/pdist-bootcheck" +install_data pdist/pdist-bootcheck.service "$DESTDIR$systemdunitdir/pdist-bootcheck.service" postinstall exit diff --git a/pdist/pdist-bootcheck b/pdist/pdist-bootcheck new file mode 100755 index 00000000..3c8e4f1a --- /dev/null +++ b/pdist/pdist-bootcheck @@ -0,0 +1,42 @@ +#! /bin/bash + +set -e + +if [ -e /.pdist_status ]; then + now=$(date +%s) + if [ $now -lt $(date +%s -d 2023-06-01) ]; then + echo $(date -d $now): implausible system time + exit 1 + fi + echo "system time: $(date -d @$now)" + pdist_time=$(stat -c%Y /.pdist_status) + echo "pdist time: $(date -d @$pdist_time)" + pdist_age=$(( ($now - $pdist_time) /60 /60 /24 )) + echo "pdist age: $pdist_age days" + if [ $pdist_age -ge 7 ]; then + need_pdist_and_reboot=1 + elif [ $pdist_age -ge 1 ]; then + need_async_pdist=1 + else + echo no update required + fi +else + echo "no recorded update time" + need_pdist_and_reboot=1 +fi + +if [ "$need_async_pdist" ]; then + netcat $(distmaster) 237 >/dev/null 2>&1