Skip to content

Commit

Permalink
[ #12 ] Adding scheduled shutdown
Browse files Browse the repository at this point in the history
This commit adds support for a new global directive "ShutdownTime", like ContestTimes or ConfigExpirationTime, that schedules a shutdown at the time defined.
  • Loading branch information
DT3264 committed Jun 2, 2023
1 parent 9b027cc commit 3d4827f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions base-system/usrroot/usr/lib/hsync/libhapply.so
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ apply_global_directives() {
set_timezone
set_keyboards
set_current_keyboard
set_scheduled_shutdown

return 0 # success
}
Expand Down Expand Up @@ -404,3 +405,22 @@ set_wallpaper() {
log "-Couldn't find any background to restore"
return 1 # error
}

set_scheduled_shutdown() {
SHUTDOWN_TIME="$(get_directives_var Global ShutdownTime)"
if [ "$SHUTDOWN_TIME" = "none" ]; then
return 0
fi
log "Cancelling scheduled poweroff (if any)"
shutdown -c
SHUTDOWN_TIME_EPOCH=$(date -d "$SHUTDOWN_TIME" +%s)
CURRENT_TIME_EPOCH=$(date +%s)
SECONDS_TO_SHUTDOWN=$((SHUTDOWN_TIME_EPOCH-CURRENT_TIME_EPOCH))
if [ "$SECONDS_TO_SHUTDOWN" -lt 0 ]; then
log "Current shutdown is for a time that already happened, skiping scheduled shutdown."
exit 0
fi
MINUTES_TO_SHUTDOWN=$((SECONDS_TO_SHUTDOWN/60))
log "Scheduling shutdown in $MINUTES_TO_SHUTDOWN minute(s)"
shutdown +"$MINUTES_TO_SHUTDOWN"
}
1 change: 1 addition & 0 deletions base-system/usrroot/usr/lib/hsync/libhupdate.so
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ have_global_config_changed() {
is_var_equal "DefaultKeyboardLayout" "$CURRENT_DIRECTIVES" "$NEW_DIRECTIVES" || return 0 # true, have-changed
is_var_equal "EventConfig" "$CURRENT_DIRECTIVES" "$NEW_DIRECTIVES" || return 0 # true, have-changed
is_var_equal "ContestConfig" "$CURRENT_DIRECTIVES" "$NEW_DIRECTIVES" || return 0 # true, have-changed
is_var_equal "ShutdownTime" "$CURRENT_DIRECTIVES" "$NEW_DIRECTIVES" || return 0 # true, have-changed

return 1 # false, have-not-changed
}
Expand Down
4 changes: 2 additions & 2 deletions base-system/usrroot/usr/sbin/hos-dvar
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ main() {
help
exit 0
;;
"--variable-name")
"--variable-name" | "-v")
VAR_NAME="$2"
shift 2
;;
"--section")
"--section" | "-s")
SECTION="$2"
shift 2
;;
Expand Down
12 changes: 12 additions & 0 deletions docs/usage/directives/configurations/shutdown-time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Shutdown time

`ShutdownTime=[ ISO8601_TIME | none ]`

Allows to set a specific time in the global section when the instances should shutdown.

Example:

`ShutdownTime=2023-06-02T13:58:00`

Note:
It might happen that (although every machine will turn off) not every machine will shut down at the same time because the shutdown command used doesn't have an accuracy of seconds, so it is expected that some computers power off in groups or one after another.

0 comments on commit 3d4827f

Please sign in to comment.