Skip to content
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

Closed
wants to merge 55 commits into from

Conversation

Dashboy1998
Copy link
Contributor

@Dashboy1998 Dashboy1998 commented Feb 15, 2024

Context

Choices

Test instructions

Auto reboot

  • Set AUTO_REBOOT_CRON_EXPRESSION close to your current time
  • Set AUTO_REBOOT_ENABLED to true
  • Set AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE to true
  • Set AUTO_REBOOT_WARN_MINUTES to 5

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

  • Set UPDATE_CRON_EXPRESSION close to your current time
  • Set AUTO_UPDATE_ENABLED to true
  • Set AUTO_REBOOT_WARN_MINUTES to 5
  • Set UPDATE_ON_BOOT to true
  • After the server starts change the buildId on line 33 in the file `palworld\steamapps\appmanifest_2394010.acf`` to any other value (for example 63707356556294349890)

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

  • I have performed a self-review of my code
  • I've added documentation about this change to the README.
  • I've not introduced breaking changes.

@Luatan
Copy link
Contributor

Luatan commented Feb 15, 2024

Test instructions

  1. Set UPDATE_CRON_EXPRESSION to */5 * * *

needs to be "*/5 * * * *"

  1. Set WARN_MINUTES to 2
  2. check in the log that the cronjob is running correctly
  3. change the buildId on line 11 in the file `palworld\steamapps\appmanifest_2394010.acf`` to any other value (for example 13289561)

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.
My suggestion would be to have set intervals. For example:
30 15 10 5 2 1

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.

@Dashboy1998
Copy link
Contributor Author

Test instructions

  1. Set UPDATE_CRON_EXPRESSION to */5 * * *

needs to be "*/5 * * * *"

  1. Set WARN_MINUTES to 2
  2. check in the log that the cronjob is running correctly
  3. change the buildId on line 11 in the file `palworld\steamapps\appmanifest_2394010.acf`` to any other value (for example 13289561)

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.
My suggestion would be to have set intervals. For example:
30 15 10 5 2 1

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.

@Dashboy1998 Dashboy1998 changed the title Auto Update add countdown Move countdown to function for auto update and auto reboot Feb 16, 2024
scripts/helper_functions.sh Outdated Show resolved Hide resolved
scripts/helper_functions.sh Outdated Show resolved Hide resolved
scripts/auto_reboot.sh Outdated Show resolved Hide resolved
scripts/auto_reboot.sh Show resolved Hide resolved
@Dashboy1998 Dashboy1998 marked this pull request as draft February 17, 2024 18:57
@Dashboy1998 Dashboy1998 marked this pull request as ready for review February 17, 2024 20:54
Comment on lines 248 to 285
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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +19 to +21
if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
fi
Copy link
Contributor

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.

Suggested change
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"

Copy link
Contributor Author

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

Copy link
Contributor

@Luatan Luatan Feb 18, 2024

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).

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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/update.sh Outdated Show resolved Hide resolved
scripts/start.sh Outdated Show resolved Hide resolved
Comment on lines 17 to 22
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
Copy link
Contributor

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.

Copy link
Contributor Author

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

@Luatan
Copy link
Contributor

Luatan commented Feb 18, 2024

Nice work!

(#356) this now has the features for/from the following

As far as I can tell a reboot policy is is still needed for the container both reboot and update. right?

@Dashboy1998
Copy link
Contributor Author

Nice work!

(#356) this now has the features for/from the following

As far as I can tell a reboot policy is is still needed for the container both reboot and update. right?

Yes.

@Dashboy1998 Dashboy1998 marked this pull request as draft February 19, 2024 20:48
@Dashboy1998
Copy link
Contributor Author

This has turned into a very big PR. I am going to break into smaller ones.

@Dashboy1998
Copy link
Contributor Author

Still need a PR for countdown function however this will be after #411 and #412

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants