-
-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move countdown to function for auto update and auto reboot #392
Conversation
needs to be "*/5 * * * *"
I think you mean to change the manifestid on line 32 right? Then it works 😊 Do we really want to send an notification every minute? I think that's a bit too many if the default is 30 minutes. And if the auto_reboot and auto_update use this, I think it would also be a good idea to make a helper function for it. |
Ah the mistakes when I copy the instructions from another PR. I just did every minute because that's what the auto reboot does. I can add a case statement so it's not every minute. |
Co-authored-by: Luatan <[email protected]>
Co-authored-by: Luatan <[email protected]>
… if players are in the server.
scripts/helper_functions.sh
Outdated
for ((i = "${mtime}" ; i > 0 ; i--)); do | ||
if [ "$(get_player_count)" -eq 0 ]; then | ||
break | ||
fi | ||
if [ "$i" -eq 1 ]; then | ||
broadcast_command "${message_prefix}_in_${i}_minute" | ||
sleep 30s | ||
broadcast_command "${message_prefix}_in_30_seconds" | ||
sleep 20s | ||
broadcast_command "${message_prefix}_in_10_seconds" | ||
sleep 10s | ||
else | ||
case "$i" in | ||
"$mtime" ) | ||
;& | ||
15 ) | ||
;& | ||
10 ) | ||
;& | ||
5 ) | ||
;& | ||
2 ) | ||
broadcast_command "${message_prefix}_in_${i}_minutes" | ||
;& | ||
* ) | ||
sleep 1m | ||
;; | ||
esac | ||
fi | ||
done | ||
return 0 | ||
else | ||
# mtime is not an integer so check if there are no players | ||
if [ "$(get_player_count)" -gt 0 ]; then | ||
return_val=1 | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to negate if [[ "${mtime}" =~ ^[0-9]+$ ]]; then
to reduce nested code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have that because the only time this is called is during a shutdown for update or reboot.
I believe both of those should happen regardless if there's a timer or not as the timer is just to let players know. If there is no timer set and there are no players I believe the action should proceed.
if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then | ||
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would need to cancel the update if WARN_MINUTES is not an integer.
if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then | |
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" | |
fi | |
if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then | |
LogError "AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}. Please check your environment variables" | |
DiscordMessage "AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}. Please check your environment variables" "failure" | |
exit 1 | |
fi | |
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have it like that because if you so choose you could run the update script with no one in the server and it will update.
Also if it is a cron job and there is no one why not just update? The timer is supposed to just let players know and not prevent the update as that's what the enable flag is for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. For me it just seems like we are allowing the user to misconfigure the env variables, which feels wrong. I think we should tell the user to fix it, but maybe we should do that in the start.sh then. To do it immediately and not wait until the update / reboot takes place.
If the user wants to have the server restart immediately they could just set WARN_MINUTES to 0 (not sure if that works as expected, haven't tested that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should still be checking in backup.sh, restore.sh, and update.sh as those are also intended to be started by the user and not just cron.
I would say for another PR we add validation for all variables which are an expected type such as int, float, boolean.
The implementation in 0.26.0 is no validation for AUTO_UPDATE_WARN_MINUTES.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it some more auto update and auto reboot should be their own script and then have a separate scripts which are to be ran by the user.
Because in my mind the user should be able to run update and tell it how long to wait or reboot instantly whereas now you can run it but you don't set the values.
This should definitely be a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better, if we added arg flags to the script instead of doing it interactively? Or both. Then we can call the script with the flags from the cronjob and if the user does not supply any flags it asks for them. That way we only have to manage one file.
Just an idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the user interactive script would just be a wrapper for the non interactive script.
scripts/auto_reboot.sh
Outdated
elif [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then | ||
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" | ||
exit 1 | ||
else | ||
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do these checks before you start the countdown. Would make it a bit cleaner in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have it like that because if you so choose you could run the reboot script with no one in the server and it will reboot.
Also if it is a cron job and there is no one why not just reboot? The timer is supposed to just let players know and not prevent the reboot as that's what the enable flag is for
Nice work!
As far as I can tell a reboot policy is is still needed for the container both reboot and update. right? |
Co-authored-by: Luatan <[email protected]>
Yes. |
This has turned into a very big PR. I am going to break into smaller ones. |
Context
Due to all the changes in Introduced Utility Functions - Remove duplicate code snippets #356 this now has the features for/from the following
$?
in favor ofif command
Auto update outputs a single message to the server saying it will update in N minutes whereas auto reboot outputs a message counting down N minutes.
Choices
Test instructions
Auto reboot
Players in game and messages
Join the server and verify that the server restarts in 5 minutes after the cronjob has started and you receive messages for 5, 2, 1 minutes, and 30, 10 seconds.
Players leave game during countdown
Join the server and once the cronjob starts leave the game and verify it restarts on the minute after you left.
Auto Update
Players in game and messages
Join the server and verify that the server restarts in 5 minutes after the cronjob has started and you receive messages for 5, 2, 1 minutes, and 30, 10 seconds.
Players leave game during countdown
Join the server and once the cronjob starts leave the game and verify it restarts on the minute after you left.
Checklist before requesting a review