diff options
| author | erkin <e.altunbas@vyos.io> | 2021-02-06 14:38:16 +0300 |
|---|---|---|
| committer | erkin <e.altunbas@vyos.io> | 2021-02-06 14:38:16 +0300 |
| commit | aed34f6991b6e87a3f178b95a13fccb7953a3dc9 (patch) | |
| tree | 1d8544480c0acb9e5fc0d768dbf74637791f076f /scripts/commit-confirm-notify.py | |
| parent | 74dafca28ac91a166851d2fd718a9d6bc18f3511 (diff) | |
| download | vyatta-config-mgmt-aed34f6991b6e87a3f178b95a13fccb7953a3dc9.tar.gz vyatta-config-mgmt-aed34f6991b6e87a3f178b95a13fccb7953a3dc9.zip | |
T3285, T661: Schedule commit-confirm reboots through systemd
Notify logged in users of the impending reboot
Diffstat (limited to 'scripts/commit-confirm-notify.py')
| -rwxr-xr-x | scripts/commit-confirm-notify.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/commit-confirm-notify.py b/scripts/commit-confirm-notify.py new file mode 100755 index 0000000..eb7859f --- /dev/null +++ b/scripts/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) |
