GameServerManagers / LinuxGSM

The command-line tool for quick, simple deployment and management of Linux dedicated game servers.
https://linuxgsm.com
MIT License
4.18k stars 802 forks source link

feat(cron): add toggle-cronjobs command #4508

Open MicLieg opened 4 months ago

MicLieg commented 4 months ago

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

Checklist

PR will not be merged until all steps are complete.

Documentation

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

Thank you for your Pull Request!

dgibbs64 commented 4 months ago

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