Cron jobs on your own server, without editing crontab.
A cron job is a command a server runs on a schedule. ServerDog manages them from your Mac: you give a job a name, a command, the Linux user it runs as and a schedule, and the server writes it into a cron file it keeps for ServerDog’s jobs. Each run’s output and exit code are recorded, so you can see whether last night’s job worked. For Laravel, one switch runs the scheduler every minute.
By ServerDog. Updated .
Key facts
- A cron schedule has five fields: minute, hour, day of the month, month and day of the week. */5 * * * * means every five minutes.
- ServerDog’s scheduled jobs run with /bin/sh in the home folder of the user you choose, at the server’s own time.
- Each job’s output goes to the server’s journal, and ServerDog records the start, finish and exit code of its latest run.
- Laravel and Statamic sites have a Scheduler switch that runs php artisan schedule:run every minute in the live release, as the site’s user.
- A server can have up to 50 scheduled jobs. They run whether or not your Mac is on.
How do I add a cron job in ServerDog?
- Open the server and choose Jobs, then New Job.
- Give the job a name and enter its command on one line.
- Enter the Linux user it runs as, such as
rootor a site’s user. - Pick a schedule, or type your own, and save.
cron runs the command with /bin/sh in that user’s home folder, so a command that needs a site’s code changes
into its folder first:
cd /home/serverdog/example.com/current && php artisan reports:send
The site’s path and user are shown in its settings. Use current, which always points at the live release.
How is a cron schedule written?
As five fields separated by spaces. A star means “every”.
| Position | Field | Values |
|---|---|---|
| 1 | Minute | 0 to 59 |
| 2 | Hour | 0 to 23 |
| 3 | Day of the month | 1 to 31 |
| 4 | Month | 1 to 12 |
| 5 | Day of the week | 0 to 7, where 0 and 7 are Sunday |
A comma lists values, a dash gives a range and a slash gives a step: 0 9-17 * * 1-5 is every hour from 9:00
to 17:00, Monday to Friday. ServerDog also accepts cron’s macros, such as @daily, @hourly and
@reboot.
Which schedules can I pick without writing one?
| Schedule | As cron writes it |
|---|---|
| Every minute | * * * * * |
| Every five minutes | */5 * * * * |
| Hourly | 0 * * * * |
| Nightly | 0 0 * * * |
| Weekly | 0 0 * * 0 |
| Monthly | 0 0 1 * * |
| At boot | @reboot |
Times are the server’s. Nightly means midnight by the server’s clock.
How do I run the Laravel scheduler?
Laravel’s scheduler needs one cron entry that runs php artisan schedule:run every minute; Laravel then
decides which of your scheduled tasks are due. In ServerDog, open the site’s Settings and turn on
Scheduler under Processes.
The server adds an entry that runs the command in the site’s live release, as the site’s user and on the site’s PHP version. Each minute starts its own run, so a long task doesn’t delay the next minute’s. The scheduler appears in the server’s Jobs tab next to your other jobs. Statamic sites have the same switch.
How do I see what a job did?
Each job’s output goes to the server’s journal under the job’s own name, and ServerDog marks the start and the exit code of every run. The Jobs tab shows the latest run, whether it failed, and the last lines the job wrote. A job fails when its command exits with a code other than zero.
What does ServerDog check before saving a job?
- The command is one line of at most 1,000 characters.
- The user exists on the server.
- The schedule is five cron fields or a macro and nothing else, so a schedule can’t carry a command of its own.
ServerDog keeps its jobs in a cron file of its own and rewrites that file from the whole list on every change. Cron entries you added elsewhere on the server are left alone.
What ServerDog does not do
- It does not ping an outside service when a job runs. If you need to know that a job stopped running, add a heartbeat request to its command.
- It does not run jobs more often than once a minute, which is cron’s limit. For that, use a background process.
Go deeper
Questions
What is a cron job?
A cron job is a command a server runs on a schedule, such as every minute or every night. The schedule is written as five fields: minute, hour, day of the month, month and day of the week.
How do I set up the Laravel scheduler on a VPS?
Laravel needs one cron entry that runs php artisan schedule:run every minute as the site’s user. In ServerDog you turn on the Scheduler switch in the site’s settings, and the server adds that entry for the site’s live release.
What does * * * * * mean in cron?
Every minute. Each of the five fields is a star, which means “every”: every minute of every hour, every day of the month, every month, every day of the week.
Which time zone do cron jobs use?
The server’s own time. A job set for 0 3 * * * runs at 3:00 by the server’s clock, not by your Mac’s.
How do I know whether a cron job ran?
ServerDog records each run’s start, finish and exit code and keeps the job’s output in the server’s journal. The app shows the latest run, whether it failed, and the last lines the job wrote.
Do cron jobs run when my Mac is off?
Yes. The jobs are in a cron file on the server and cron runs them there. Your Mac is only needed to change them or look at their output.
What happens to a running job if I remove it?
cron stops starting it. A run that is already in progress finishes.
Last updated by ServerDog.