LinuxGSM icon indicating copy to clipboard operation
LinuxGSM copied to clipboard

feat(cron): add toggle-cronjobs command

Open MicLieg opened this issue 11 months ago • 2 comments

Description

This pull request introduces a new command: ./gameserver toggle-cronjobs

This command simplifies cronjob management for LinuxGSM users and auto deployment scripts, making it easier to ensure that server monitoring, updates, and restarts are performed automatically according to the specified schedules.

The toggle-cronjobs command operates by identifying whether cronjobs, using the specified LinuxGSM commands, exist within the system's crontab and wehter these were aded by LinuxGSM:

  1. If there is no cronjob using the specified LinuxGSM command, a new cronjob will be created for the specified command.
  2. If there is a cronjob using the specified LinuxGSM command that was added by LinuxGSM, the cronjob will be removed.
  3. If there is a cronjob using the specified LinuxGSM command that was NOT added by LinuxGSM, the specified LinuxGSM command will be skipped and no cronjob will be added or removed.

I've chosen to include similar cronjobs as the Example cronjobs:

fn_toggle_cronjob "monitor" "*/5 * * * *" # Every 5 minutes fn_toggle_cronjob "update" "*/30 * * * *" # Every 30 minutes fn_toggle_cronjob "update-lgsm" "0 0 * * *" # Daily at midnight fn_toggle_cronjob "restart" "30 4 * * *" # Daily at 4:30am

Currently the output of all LinuxGSM managed cronjobs including all erros will be sent to /dev/null. It might be woth saving the logs to LinuxGSM's log dir.

Fixes #4329

Type of change

  • [ ] Bug fix (a change which fixes an issue).
  • [x] New feature (a change which adds functionality).
  • [ ] New Server (new server added).
  • [ ] Refactor (restructures existing code).
  • [ ] Comment update (typo, spelling, explanation, examples, etc).

Checklist

PR will not be merged until all steps are complete.

  • [x] This pull request links to an issue.
  • [x] This pull request uses the develop branch as its base.
  • [x] This pull request subject follows the Conventional Commits standard.
  • [x] This code follows the style guidelines of this project.
  • [x] I have performed a self-review of my code.
  • [x] I have checked that this code is commented where required.
  • [x] I have provided a detailed enough description of this PR.
  • [ ] I have checked if documentation needs updating.
    • I will add documentation once I get feedback on whether this PR will be merged.

Documentation

If documentation does need updating either update it by creating a PR (preferred) or request a documentation update.

  • User docs: https://github.com/GameServerManagers/LinuxGSM-Docs
  • Dev docs: https://github.com/GameServerManagers/LinuxGSM-Dev-Docs

Thank you for your Pull Request!

MicLieg avatar Feb 25 '24 14:02 MicLieg

Very nice PR. Will take me a little time to review and test properly. But overall I like it 👍🏻

dgibbs64 avatar Feb 26 '24 15:02 dgibbs64

Very nice PR. Will take me a little time to review and test properly. But overall I like it 👍🏻

Have you had time to test this feature in more detail?

MicLieg avatar Jul 13 '24 02:07 MicLieg