Skip to content

Cron jobs on cPanel — the policy decisions that prevent runaways

How to design a cron job policy on a multi-tenant cPanel host that prevents tenants from accidentally bringing down the box, and the limits that actually matter.

Cron jobs are the source of more “the server is slow at 3am” tickets on cPanel than almost anything else. A customer adds a “run this every minute” cron, the script takes 90 seconds to complete, and within a week there are 100 of them running concurrently. The right policy isn’t “no crons” — it’s bounded crons with enforced limits.

The trade-off

Customers need cron. WordPress cron via real cron (instead of WP’s pseudo-cron) is a meaningful performance improvement. Backup scripts, queue workers, mail jobs — all legitimate. The risk is the same as with any other resource: one tenant’s runaway cron becomes everyone’s problem.

How to decide — the policy dimensions

  1. Minimum frequency. Default cPanel allows every-minute cron. For shared hosting, raise this to every-5-minutes (or higher for low-tier plans). cPanel doesn’t enforce minimum interval natively; you enforce by educating customers and via LVE limits.
  2. Maximum running time. Use timeout in cron commands: timeout 60 /home/user/script.sh. Document this as standard practice.
  3. Concurrent execution. Use flock to prevent the same cron from running twice if the previous instance hasn’t finished: flock -n /tmp/cron.lock /home/user/script.sh.
  4. Resource limits per cron. LVE applies to cron jobs via lveuser_set if you want different limits than the user’s standard LVE.
  5. Logging. Output should go to a tenant-visible log file with rotation, not to email-on-stdout (which floods Exim).
  6. Lower bound on actual frequency. Some “every minute” cron jobs only need to run hourly. Audit periodically.

What to do — operator policy

  1. Publish a cron policy in your plan documentation. “Crons may not run more than once every 5 minutes on Standard plans” is a defensible position.
  2. Default new accounts to crontab restricted via PAM or by stripping the crontab binary on lowest-tier plans.
  3. Monitor cron CPU contribution per tenant. lveinfo --period=1d --by-fault=cpu filtered to identify cron-driven faults.
  4. Document the patterns customers should use:
    • timeout to cap runtime
    • flock to prevent overlap
    • Log redirection to file, not email
    • Random offset to prevent thundering herd (e.g., * * * * * sleep $((RANDOM % 30)); /home/user/script.sh)
  5. Reach out to tenants whose crons cause issues before they cause an outage. Most customers don’t realize their cron is the problem.
  6. Provide a sandbox cron environment for testing. Customers shouldn’t debug crons in production.
  7. For the WordPress-specific case, replace WP’s pseudo-cron with real cron via WHM > MultiPHP Manager, but enforce a reasonable frequency.

Stack Harbor sets and enforces cron policy as part of cPanel/WHM management.