Bỏ qua để đến nội dung
Cron jobs Schedule, run and inspect cron jobs on a server — with per-job run logs.

Cron jobs

Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.

The Cron jobs section of a server (/servers/:id/cron) manages the scheduled tasks on that box. MZPanel gives its own jobs a full lifecycle — create, run, pause, edit, delete, and per-run logs — while showing the machine’s existing system cron read-only so nothing is hidden from you. It’s available on all plans.

  1. Click New job to open the create drawer.
  2. Enter a Name, the Command to run, and pick the Run as user (populated from the box’s real system users).
  3. Set the Schedule: pick a preset (every minute, hourly, daily at 03:00, weekly, @reboot, …) or type a raw cron expression — a colour-coded five-field breakdown shows exactly when it will fire. Prefer to paste? Switch to paste full line and drop in a whole crontab line; MZPanel splits it into the fields for you.
  4. Optional: under Failure detection, add patterns that mark a run failed by its output (see below).
  5. Save. The job appears in the list with a live countdown to its next run.

A run always counts as failed when the command exits non-zero. Many commands (PHP scripts, wp and artisan calls, curl health pings) print an error and still exit 0, so a job can also be judged by what it prints:

  • Fail when the output contains: one pattern per line, up to 10. Any match marks the run failed, even with exit 0.
  • Succeed only if the output contains: one optional pattern; the run is failed when the output lacks it (for example Backup complete).

A pattern is plain text matched case-insensitively, or a regular expression when you write it as /…/ (RE2 syntax, also case-insensitive, for example /error [0-9]+/). Each pattern is one line of at most 200 characters. The check reads the last 64 KB of the run’s combined stdout and stderr.

A run failed by an output check shows Failed on the card with the reason (output matched "Fatal error" or output did not contain "Backup complete"), and View logs shows the same reason on that run next to its real exit code. Run now applies the same check and ends with failed: <reason>. A failed run, by exit code or by output, raises the Cron job failed notification (cron.failed); route it to a channel in Chat & alerts. It fires at most once per job per hour.

Limits:

  • Output checks need agent 0.2.166 or newer. On an older agent, saving patterns answers agent_update_required; update the agent first.
  • The run-logger only wraps a host command without shell operators (; | && || ` $(), so the agent refuses output checks on such a command (output_check_unsupported). Move the pipeline into a script and schedule the script. Container tasks are always wrapped, so any command works there.

The page is a searchable list of job cards, each showing status, name, schedule, command, run-as user, last run, and a live next run countdown.

  • Filter and search — by status (All / Active / Failing / Paused) or type (Sites, MZPanel, System), and search across name, command, schedule, user and site.
  • Site cron of every runtime — Sites covers per-site jobs of any type, not only WordPress: Laravel php artisan schedule:run, Symfony bin/console, Django manage.py, and Node / Python / Go scripts that live in a site’s folder. A job is matched to its site by the site’s Linux user, its web root or home (/home/<site-user>/…), or its domain in the command, and the card shows that site’s domain. Everything else (OS and package maintenance) stays under System. A Laravel site created by MZPanel already has its schedule:run entry (mz-site-<user>-scheduler), shown under the site here; switch it on or off with site.laravel (see Laravel) rather than adding another.
  • Run now — trigger a job immediately; its output streams live in a drawer, ending with the exit code.
  • View logs — open the run history: newest-first records, each expandable to show exit code, duration and captured output.
  • Pause / resume, edit, and delete a panel-created job.
  • Container tasks — a job can run inside a Docker container: the runner wraps the command in docker exec. Create these from the Tasks tab of a container or stack drawer in Apps; they show here with an in <container> chip and share the same run logs (cron.add with container).

Actions on this page dispatch cron.* jobs to the server’s agent, which runs them natively:

ActionJobAgent runs
Listcron.listcron list --json
Createcron.addwrites /etc/cron.d/mz-custom-<slug>
Editcron.updaterewrites the managed file
Pause / resumecron.toggleenable/disable the entry
Deletecron.removeremoves the managed file and its run log; an unknown id fails with cron_not_found
Run nowcron.runruns once, streaming stdout/stderr
View logscron.logsreads the run-log ring buffer

Panel-created jobs live in their own files under /etc/cron.d/mz-custom-*, so they never touch the machine’s existing cron. Scheduled runs go through a small run-logger that keeps the last 25 runs of each job — timestamp, exit code, duration and an output tail — under /var/log/mzcron/. That’s what View logs reads.

Every action here maps to an mz command on the box — the same engine the dashboard drives:

Terminal window
mz cron list --json # list jobs
mz cron add --schedule "0 3 * * *" \
--command "wp cron event run --due-now --path=/var/www/site" --user www-data
mz cron add --schedule "*/15 * * * *" \
--command "php artisan schedule:run" --container myapp --json # inside a container
mz cron add --schedule "0 2 * * *" --command "/home/site/backup.sh" \
--fail-on "Fatal error" --fail-on "/error [0-9]+/" --ok-if "Backup complete"
mz cron edit <id> --schedule "0 2 * * *" --command "/home/site/backup.sh" \
--no-fail-on --no-ok-if # clear the output checks
mz cron run <id> # run once, streams output
mz cron log <id> --json # a job's run history

Always pass a sub-action (mz cron alone errors) and --json for machine output. See The mz CLI and the command catalog.

GoalMCP toolJob kind
List jobsservers_inventory with kind cron, or jobs_createcron.list
Create / editjobs_createcron.add {schedule, command, user?, comment?, container?, failPatterns?, successPattern?}, cron.update
Pause / resume / deletejobs_createcron.toggle, cron.remove
Run once / read logsjobs_createcron.run, cron.logs

Because a cron job runs an arbitrary command as a system user, cron.add and cron.update need a full-level token plus the system:admin scope. Call jobs_schema with cron.add for the exact field formats.

Output checks: failPatterns (array, up to 10) and successPattern (string) on cron.add and cron.update. On cron.update, sending either field replaces the job’s whole rule set (failPatterns: [] clears it); sending neither keeps the current rules. The cron inventory reports each managed job’s fail_patterns, success_pattern and, when an output check failed the newest run, last_reason; cron.logs records carry status and reason. The developer webhook / event feed event cron.failed carries {server_id, id, name, command, exit, reason?, at?, container?}.

  • System / non-MZPanel cron is read-only. On a live server, only MZPanel-managed jobs can be edited, paused, run or deleted; existing system/package cron is shown for visibility but never rewritten. System jobs are hidden by default — pick the System type filter to see them.
  • A job keeps failing with exit 0. It has an output check that matches: open View logs, read the reason on the run, and fix the command or the pattern. A pattern that also occurs in normal output (for example error in 0 errors) needs a tighter regex such as /[1-9][0-9]* errors/.
  • “Run now” isn’t written to the log. A manual run streams its output live but is intentionally not added to the run-log — the log records the scheduled runs. Use Run now to test, View logs to audit the schedule.
  • Delete says cron_not_found. No managed job has that id on the server: it was typed wrong or is already gone (deleting a site also removes the jobs that ran as its user). Nothing was changed; refresh the list and pick the id from there.
  • Offline servers show cached cron. The list renders from the last known state; creating, running, or viewing live logs needs the agent online.
  • WordPress sites don’t need per-site cron. A single box-wide dispatcher runs every minute and fans out to every WP site on a stagger, so you won’t (and shouldn’t) create a wp-cron entry per site here.