-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#12] Adding scheduled shutdown service
This commit adds support for a new global directive "ShutdownTime", like ContestTimes or ConfigExpirationTime, that schedules a shutdown at the time defined. This aproach instead of calculating when to shutdown, checks every minute if the system is ready to shutdown, checks including - Is clock in sync - Is there a scheduled time to shutdown - Is time to shutdown - Is system in always mode (I think it would not be expected / allowed to shutdown the system while in contest / event mode, right?)
- Loading branch information
Showing
5 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
base-system/usrroot/usr/lib/systemd/system/hypnotizer.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Unit] | ||
Description=Service to check if is time to shutdown the machine | ||
|
||
[Service] | ||
ExecStart=/usr/sbin/hypnotizer | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
13 changes: 13 additions & 0 deletions
13
base-system/usrroot/usr/lib/systemd/system/hypnotizer.timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=TImer to check if is time to shutdown the machine | ||
|
||
|
||
[Timer] | ||
AccuracySec=1s | ||
OnUnitInactiveSec=60s | ||
OnBootSec=1s | ||
OnClockChange=false | ||
OnTimezoneChange=false | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
. /usr/lib/hsync/libhlog.so | ||
|
||
## Check if clock is in sync, otherwise the current time is untrusted | ||
STATE_IS_CLOCK_SYNC=$(timedatectl show | grep NTPSynchronized | cut -d= -f2) | ||
if [ "$STATE_IS_CLOCK_SYNC" = "no" ]; then | ||
log "System time is not in sync, exiting" | ||
fi | ||
|
||
## Getting the shutdown time | ||
# SHUTDOWN_TIME="2023-09-02T15:05:00" | ||
# SHUTDOWN_TIME="$(get_directives_var Global )" | ||
SHUTDOWN_TIME="$(hos-dvar --variable-name ShutdownTime --section Global)" | ||
if [ -z "$SHUTDOWN_TIME" ] || [ "$SHUTDOWN_TIME" = "none" ]; then | ||
log "No shutdown scheduled, exiting." | ||
exit 0 | ||
fi | ||
|
||
## Getting the remaining time to shutdown | ||
SHUTDOWN_TIME_EPOCH=$(date -d "$SHUTDOWN_TIME" +%s) | ||
CURRENT_TIME_EPOCH=$(date +%s) | ||
SECONDS_TO_SHUTDOWN=$((SHUTDOWN_TIME_EPOCH - CURRENT_TIME_EPOCH)) | ||
## If secondsToShutdown > 0: don't shutdown yet | ||
## If secondsToShutdown < 0: try to shutdown | ||
if [ "$SECONDS_TO_SHUTDOWN" -gt 0 ]; then | ||
log "Scheduled shutdown scheduled for later, exiting" | ||
exit 0 | ||
fi | ||
|
||
## If we're not in always mode, exit | ||
## We don't want to ruin neither an event or a contest | ||
if [[ $(hos-dmode) != "Always" ]]; then | ||
log "The system will shut down as soon as it goes to Always mode, exiting" | ||
exit 0 | ||
fi | ||
|
||
# If we hit this point, is totally safe to shutdown | ||
log "The starts aligned, shutting down the system" | ||
shutdown -h now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters