Avoid OAuth2 refresh token expiry by forcing a notification target
refresh in PVE's daily-update job.

This is done under a notifications config lock because failure to do so
may result in the state file updates happening concurrently with other
configuration file updates, leading to, for example, a stale state file
if an endpoint was deleted in the meantime.

Signed-off-by: Arthur Bied-Charreton <[email protected]>
---
 bin/pveupdate | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/bin/pveupdate b/bin/pveupdate
index b1960c35..25cd4f21 100755
--- a/bin/pveupdate
+++ b/bin/pveupdate
@@ -195,4 +195,17 @@ sub cleanup_tasks {
 
 cleanup_tasks();
 
+eval {
+    PVE::Notify::lock_config(sub {
+        my $config = PVE::Notify::read_config();
+        # Refresh internal state for notification targets. This writes the
+        # state files for SMTP XOAUTH2 endpoints, which we do not want to
+        # happen concurrently with config R/W cycles.
+        $config->trigger_state_refresh();
+    });
+};
+if (my $err = $@) {
+    syslog('err', "refresh notification targets failed: $err");
+}
+
 exit(0);
-- 
2.47.3



Reply via email to