summaryrefslogtreecommitdiff
path: root/src/helpers/commit-confirm-notify.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-04-17 13:00:48 +0200
committerGitHub <noreply@github.com>2021-04-17 13:00:48 +0200
commit981153d79783ededa7188a0e397ead0895cd7076 (patch)
tree89c15635d7757821ca48bbf6c646f3a8f6c92634 /src/helpers/commit-confirm-notify.py
parent6a08795adb9ab60d1ff26946fdff9a5442b0be6f (diff)
parent3604ccf91f0615d6d51310bb74109eb1594e7173 (diff)
downloadvyos-1x-981153d79783ededa7188a0e397ead0895cd7076.tar.gz
vyos-1x-981153d79783ededa7188a0e397ead0895cd7076.zip
Merge pull request #812 from erkin/current
T3472: Move over commit-confirm-notify.py from vyatta-config-mgmt
Diffstat (limited to 'src/helpers/commit-confirm-notify.py')
-rwxr-xr-xsrc/helpers/commit-confirm-notify.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/helpers/commit-confirm-notify.py b/src/helpers/commit-confirm-notify.py
new file mode 100755
index 000000000..eb7859ffa
--- /dev/null
+++ b/src/helpers/commit-confirm-notify.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+import os
+import sys
+import time
+
+# Minutes before reboot to trigger notification.
+intervals = [1, 5, 15, 60]
+
+def notify(interval):
+ s = "" if interval == 1 else "s"
+ time.sleep((minutes - interval) * 60)
+ message = ('"[commit-confirm] System is going to reboot in '
+ f'{interval} minute{s} to rollback the last commit.\n'
+ 'Confirm your changes to cancel the reboot."')
+ os.system("wall -n " + message)
+
+if __name__ == "__main__":
+ # Must be run as root to call wall(1) without a banner.
+ if len(sys.argv) != 2 or os.getuid() != 0:
+ exit(1)
+ minutes = int(sys.argv[1])
+ # Drop the argument from the list so that the notification
+ # doesn't kick in immediately.
+ if minutes in intervals:
+ intervals.remove(minutes)
+ for interval in sorted(intervals, reverse=True):
+ if minutes >= interval:
+ notify(interval)
+ minutes -= (minutes - interval)
+ exit(0)