From 7265757458772ae728ee4970636b9133e9e5a1ac Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Wed, 10 Jan 2024 23:48:27 +0200 Subject: [PATCH] Automation update --- automation/composer.json | 2 +- automation/cron.php | 153 ++++++------------------------------- automation/crontab.example | 57 -------------- docs/install.md | 7 +- docs/install.sh | 2 +- 5 files changed, 27 insertions(+), 194 deletions(-) delete mode 100644 automation/crontab.example diff --git a/automation/composer.json b/automation/composer.json index 48e37d6..8f51b88 100644 --- a/automation/composer.json +++ b/automation/composer.json @@ -7,6 +7,6 @@ "monolog/monolog": "^3.5", "league/flysystem": "^3.23", "league/flysystem-sftp-v3": "^3.22", - "pinga/crontab": "^1.0" + "peppeocchi/php-cron-scheduler": "^4.0" } } diff --git a/automation/cron.php b/automation/cron.php index 0e5c533..0ccab93 100644 --- a/automation/cron.php +++ b/automation/cron.php @@ -1,12 +1,4 @@ false, // Set to true to enable ]; -// Zone Generator -$writezone = new Worker(); -$writezone->name = 'Zone Generator'; -$writezone->onWorkerStart = function () { - new Crontab('*/15 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/write-zone.php > /dev/null 2>&1'); - }); -}; +require __DIR__ . '/vendor/autoload.php'; -// System Maintenance -$maintenance = new Worker(); -$maintenance->name = 'System Maintenance'; -$maintenance->onWorkerStart = function () { - new Crontab('35 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/registrar.php > /dev/null 2>&1'); - }); - - new Crontab('59 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/statistics.php > /dev/null 2>&1'); - }); - - new Crontab('50 1 * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/rdap-urls.php > /dev/null 2>&1'); - }); - - new Crontab('0 0 * * 1', function(){ - exec('/usr/bin/php8.2 /var/www/cp/bin/file_cache.php > /dev/null 2>&1'); - }); -}; +use GO\Scheduler; +$scheduler = new Scheduler(); -// Domain Maintenance -$domainmaint = new Worker(); -$domainmaint->name = 'Domain Maintenance'; -$domainmaint->onWorkerStart = function () { - new Crontab('30 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/change-domain-status.php > /dev/null 2>&1'); - }); - - new Crontab('45 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/auto-approve-transfer.php > /dev/null 2>&1'); - }); - - new Crontab('5 0 * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/auto-clean-unused-contact-and-host.php > /dev/null 2>&1'); - }); -}; +$scheduler->php('/opt/registry/automation/write-zone.php')->at('*/15 * * * *'); +$scheduler->php('/opt/registry/automation/registrar.php')->at('35 * * * *'); +$scheduler->php('/opt/registry/automation/statistics.php')->at('59 * * * *'); +$scheduler->php('/opt/registry/automation/rdap-urls.php')->at('50 1 * * *'); +$scheduler->php('/var/www/cp/bin/file_cache.php')->at('0 0 * * 1'); + +$scheduler->php('/opt/registry/automation/change-domain-status.php')->at('30 * * * *'); +$scheduler->php('/opt/registry/automation/auto-approve-transfer.php')->at('45 * * * *'); +$scheduler->php('/opt/registry/automation/auto-clean-unused-contact-and-host.php')->at('5 0 * * *'); -// Accounting if ($cronJobConfig['accounting']) { - $accounting = new Worker(); - $accounting->name = 'Accounting'; - $accounting->onWorkerStart = function () { - new Crontab('1 0 1 * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/send-invoice.php > /dev/null 2>&1'); - }); - }; + $scheduler->php('/opt/registry/automation/send-invoice.php')->at('1 0 1 * *'); } -// Backup if ($cronJobConfig['backup']) { - $backup = new Worker(); - $backup->name = 'Backup'; - $backup->onWorkerStart = function () { - new Crontab('15 * * * *', function(){ - exec('/opt/registry/automation/vendor/bin/phpbu --configuration=/opt/registry/automation/backup.json > /dev/null 2>&1'); - }); - - new Crontab('30 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/backup-upload.php > /dev/null 2>&1'); - }); - }; + $scheduler->raw('/opt/registry/automation/vendor/bin/phpbu --configuration=/opt/registry/automation/backup.json')->at('15 * * * *'); + $scheduler->php('/opt/registry/automation/backup-upload.php')->at('30 * * * *'); } -// Spec11 Reports if ($cronJobConfig['spec11']) { - $spec11 = new Worker(); - $spec11->name = 'Spec11 Reports'; - $spec11->onWorkerStart = function () { - new Crontab('30 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/abusemonitor.php > /dev/null 2>&1'); - }); - - new Crontab('5 0 * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/abusereport.php > /dev/null 2>&1'); - }); - }; -} - -// TMCH -if ($cronJobConfig['gtld_mode']) { - $tmch = new Worker(); - $tmch->name = 'TMCH'; - $tmch->onWorkerStart = function () { - new Crontab('10 0 * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/lordn.php > /dev/null 2>&1'); - }); - - new Crontab('0 0,12 * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/tmch.php > /dev/null 2>&1'); - }); - }; -} - -// URS -if ($cronJobConfig['gtld_mode']) { - $urs = new Worker(); - $urs->name = 'URS'; - $urs->onWorkerStart = function () { - new Crontab('45 * * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/urs.php > /dev/null 2>&1'); - }); - }; -} - -// Escrow -if ($cronJobConfig['gtld_mode']) { - $escrow = new Worker(); - $escrow->name = 'Escrow'; - $escrow->onWorkerStart = function () { - new Crontab('5 0 * * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/escrow.php > /dev/null 2>&1'); - }); - }; + $scheduler->php('/opt/registry/automation/abusemonitor.php')->at('30 * * * *'); + $scheduler->php('/opt/registry/automation/abusereport.php')->at('5 0 * * *'); } -// Reporting if ($cronJobConfig['gtld_mode']) { - $reporting = new Worker(); - $reporting->name = 'Reporting'; - $reporting->onWorkerStart = function () { - new Crontab('1 0 1 * *', function(){ - exec('/usr/bin/php8.2 /opt/registry/automation/reporting.php > /dev/null 2>&1'); - }); - }; + $scheduler->php('/opt/registry/automation/lordn.php')->at('10 0 * * *'); + $scheduler->php('/opt/registry/automation/tmch.php')->at('0 0,12 * * *'); + $scheduler->php('/opt/registry/automation/urs.php')->at('45 * * * *'); + $scheduler->php('/opt/registry/automation/escrow.php')->at('5 0 * * *'); + $scheduler->php('/opt/registry/automation/reporting.php')->at('1 0 1 * *'); } -Worker::runAll(); \ No newline at end of file +$scheduler->run(); diff --git a/automation/crontab.example b/automation/crontab.example deleted file mode 100644 index 685128e..0000000 --- a/automation/crontab.example +++ /dev/null @@ -1,57 +0,0 @@ -#----------> Crontab Configuration for Namingo <--------------------------------# - -# run write-zone.php every 15 min. -*/15 * * * * root /usr/bin/php8.2 /opt/registry/automation/write-zone.php - -# run statistics.php at 59 min, every hour -59 * * * * root /usr/bin/php8.2 /opt/registry/automation/statistics.php - -# run backup at 15 min, every hour -15 * * * * /opt/registry/automation/vendor/bin/phpbu --configuration=/opt/registry/automation/backup.json - -# run backup-upload.php at 30 min, every hour -30 * * * * root /usr/bin/php8.2 /opt/registry/automation/backup-upload.php - -# run change-domain-status.php every hour -30 * * * * root /usr/bin/php8.2 /opt/registry/automation/change-domain-status.php - -# run auto-approve-transfer.php every hour -45 * * * * root /usr/bin/php8.2 /opt/registry/automation/auto-approve-transfer.php - -# run registrar.php every hour -35 * * * * root /usr/bin/php8.2 /opt/registry/automation/registrar.php - -# run abusemonitor.php every hour -30 * * * * root /usr/bin/php8.2 /opt/registry/automation/abusemonitor.php - -# run abusereport.php every day -5 0 * * * root /usr/bin/php8.2 /opt/registry/automation/abusereport.php - -# run lordn.php every day -10 0 * * * root /usr/bin/php8.2 /opt/registry/automation/lordn.php - -# run send-invoice.php every 1st day -1 0 1 * * root /usr/bin/php8.2 /opt/registry/automation/send-invoice.php - -# run auto-clean-unused-contact-and-host.php every day -5 0 * * * root /usr/bin/php8.2 /opt/registry/automation/auto-clean-unused-contact-and-host.php - -# run tmch.php twice a day -0 0,12 * * * root /usr/bin/php8.2 /opt/registry/automation/tmch.php - -# run escrow.php every day -5 0 * * * root /usr/bin/php8.2 /opt/registry/automation/escrow.php - -# run rdap-urls.php every day -50 1 * * * root /usr/bin/php8.2 /opt/registry/automation/rdap-urls.php - -# run file_cache.php every day -0 2 * * * root /usr/bin/php8.2 /var/www/cp/bin/file_cache.php - -# run reporting.php every 1st day -1 0 1 * * root /usr/bin/php8.2 /opt/registry/automation/reporting.php - -# run urs.php every hour -45 * * * * root /usr/bin/php8.2 /opt/registry/automation/urs.php - -#----------> End Crontab Configuration for Namingo <----------------------------# \ No newline at end of file diff --git a/docs/install.md b/docs/install.md index 9e86bf0..c7cf33f 100644 --- a/docs/install.md +++ b/docs/install.md @@ -524,15 +524,12 @@ Please send the exported `publickey.asc` to your RDE provider, and also place th ### Running the Automation System -Once you have successfully configured all automation scripts, you are ready to initiate the automation system. Please proceed by executing the commands listed below: +Once you have successfully configured all automation scripts, you are ready to initiate the automation system. Please review ```/opt/registry/automation/cron.php``` and enable all services if you are running a gTLD. Then proceed by adding the following cron job to the system crontab using ```crontab -e```: ```bash -cd /opt/registry/automation -php cron.php start +* * * * * /usr/bin/php8.2 /opt/registry/automation/cron.php 1>> /dev/null 2>&1 ``` -Alternatively, you may opt for the traditional Linux crontab method. Should you choose this approach, begin by accessing the sample crontab file at ```/opt/registry/automation/crontab.example```. Carefully examine its contents, and then copy the pertinent lines into your system's crontab file. - ## 13. Setup DAS: ```bash diff --git a/docs/install.sh b/docs/install.sh index 48e6a20..c58146b 100644 --- a/docs/install.sh +++ b/docs/install.sh @@ -405,7 +405,7 @@ EOF echo -e "Next steps:\n" echo -e "1. Configure each component by editing their respective configuration files." echo -e "2. Once configuration is complete, start each service with the following command:\n systemctl start SERVICE_NAME.service\n Replace 'SERVICE_NAME' with the specific service (whois, rdap, epp, das) as needed." - echo -e "3. To set up automation services, refer to the configuration manual, edit the config in:\n /opt/registry/automation/config.php and run php /opt/registry/automation/cron.php start\n" + echo -e "3. To initiate the automation system, please refer to the configuration manual.\n" echo -e "For more detailed information, please consult the accompanying documentation or support resources." else echo "Unsupported Linux distribution or version"