PDA

View Full Version : WHMCS Cronjob 100% CPU, hosting suspended as a result



Fli
07-06-2017, 11:33 AM
My cPanel hosting account on which WHMCS billing system is running was suspended, because of the cron.php was using 100% CPU for too long time probably.

100% cpu usage


889163 myusername 20 0 664484 245148 17892 R 98.1 0.4 2:15.50 /opt/cpanel/ea-php56/root/usr/bin/php-cgi -q /home1/myusername/public_html/admin/cron.php
892138 myusername 20 0 115244 1528 1316 S 0.0 0.0 0:00.00 /bin/bash /usr/sbin/sendmail -FCronDaemon -i -odi -oem -oi -t -f myusername
892142 myusername 20 0 10468 428 324 S 0.0 0.0 0:00.00 /usr/sbin/proxyexec -c cagefs.sock myusername S90HC3y3yo0SBCO0 /home/myusername SENDMAIL 892138 -FCronD+

cron.php is a script that is ran daily in the midnight

MySQL database size is like 138MB

----------

What to do to prevent the cron.php script use too many server resources for too long time?

----------

I searched Google and this is the result what i did:

1)
WHMCS / Utilities / Logs / Activity Log, and filter out "Cron" entries.
i compared log lines from the day my account was suspended for cron.php excessive CPU usage with a day when it was not suspended (run successfully) and i found difference:

good day:
Domain Sync Cron: Completed
Domain Sync Cron: Starting
Cron Job: Email Backup - Sent Successfully
Cron Job: Backup Generation Completed
Cron Job: Starting Backup Generation
Cron Job: Starting Database Backup
Cron Job: Completed
Cron Job: Done
Cron Job: Starting Performing Client Status Sync
Cron Job: Done
Cron Job: Running Usage Stats Update for Server ID 8
Cron Job: Running Usage Stats Update for Server ID 7
Cron Job: Starting Updating Disk & Bandwidth Usage Stats

suspended day:
Cron Job: Starting Backup Generation
Cron Job: Starting Database Backup
Cron Job: Completed
Cron Job: Done
Cron Job: Starting Performing Client Status Sync
Cron Job: Done
Cron Job: Running Usage Stats Update for Server ID 8
Cron Job: Running Usage Stats Update for Server ID 7
Cron Job: Starting Updating Disk & Bandwidth Usage Stats

So in suspended day it did not completed backup generation.. mysql db size too big, probably server was also cluttered by other tasks in the midnight

2)
so i wanted to decrease database size, so i did a cleanup inside:
WHMCS / Utilities / System / System Cleanup
WHMCS / Utilities / Logs / Module Log
then optimized mysql tables with overhead inside my hosting control panel, PHPMyAdmin section

+ scheduled a reminder to prune unnecessary whmcs logs regularly

3)
i also tried to run cron.php with lowest CPU and HDD I/O priority
in hosting control panel cpanel i went into Cronjobs section and enabled e-mail sending on each cronjob. Then added minutely cronjob:
/bin/nice -n 19 /usr/bin/ionice -c2 -n7 date
it worked, i received e-mails with no error. So i edited my main cronjob from:
php -q /home1/myusername/public_html/admin/cron.php
to:
/bin/nice -n 19 /usr/bin/ionice -c2 -n7 php -q /home1/myusername/public_html/admin/cron.php
so i hope the cron.php may not trigger my hosting provider CPU anti abuse script limits when run in low priority.