Cron Configuration Reference

From Sympl Wiki
Revision as of 12:11, 19 July 2019 by Kelduum (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Each domain in Sympl can have it's own crontab to run specific jobs. This is configured the same as the normal system crontab, and is kept in /srv/example.com/config/crontab in order to keep jobs associated with domains.

Scheduling Jobs

The Sympl crontab works similarly to the normal system crontab, however the only environment variables which can be set are PATH and MAILTO.

Each line starts with five values which specify when the job should be run, followed by the command to run, separated by whitespace. Comments begin with a hash (#) and must be on a line by themselves. Hours are specified on the 24 hour clock.

minute hour day month day_of_week command_to_run

Field Allowed values
minute * 0-59 , - /
hour * 0-23 , - /
day * 1-31 , -
month * 1-12 or JAN-DEC , -
day_of_week * 0-6 or SUN-SAT , -

Commas (,) are used to separate items in lists, and hyphens (-) are ranges.

The slash (/) is preceded by an asterisk (*) and followed by a number which indicates the job should run if the minute or hour is divisible by the number, for example a minuite value of */5 will run the task every 5 minutes.

Time Shortcuts

There are a number of shortcuts for common times for jobs to run, which replaces the five values above.

@shortcut command_to_run

Shortcut Jobs Will Run
@hourly Every hour on the hour.
@daily or @midnight Every day at midnight.
@weekly Once a week on Sunday.
@monthly Each month on the 1st at midnight.
@yearly or @annually Midnight at Jan 1st each year

Note that there is no @reboot entry supported. If you need a task to run after a reboot, you will need to add it in a system crontab.

Example Configuration

# Send any output to webmaster@example.com
MAILTO=webmaster@example.com

# Run /srv/example.com/synchronise_orders.sh every 10 minutes.
*/10 * * * * /srv/example.com/synchronise_orders.sh

# Run /srv/example.com/mail_overnight_orders.sh at 9:00 on a Monday to Friday.
0 9 * * MON-FRI /srv/example.com/mail_overnight_orders.sh

# Run /srv/example.com/generate_stats.sh every day at midnight.
@daily /srv/example.com/generate_stats.sh

# Write the text "Happy New Year!" every year.
@yearly echo "Happy New Year!"

Testing Configuration

Sympl includes a parser which allows you to check the next run-time of the jobs. Run sympl-crontab --test /srv/example.com/config/crontab to get a list of the configured jobs, and their next run-time.

The above example, run on a Friday, looks like this:

Environment
-------------------------------------------------------------------------------
HOME = /home/sympl
LOGNAME = sympl
PATH = /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
MAILTO = webmaster@example.com
===============================================================================
Jobs next due -- Local time 2019-07-19 11:46:12
-------------------------------------------------------------------------------
Next Run Time       Command
-------------------------------------------------------------------------------
2019-07-19 11:50    /srv/example.com/synchronise_orders.sh
2019-07-22 09:00    /srv/example.com/mail_overnight_orders.sh
2019-07-20 00:00    /srv/example.com/generate_stats.sh
2020-01-01 00:00    echo "Happy New Year!"
===============================================================================


Configuration Reference

File or Directory Used For More
/srv/example.com/config/crontab Runs scheduled jobs as the sympl user, on a per-domain basis. More...

See also Configuration Reference for other configuration files.