Cron Configuration Reference: Difference between revisions

From Sympl Wiki
Jump to navigation Jump to search
(Created page with "{{Stub}} ==Configuration Reference== <section begin=config /> {| class="wikitable sortable" |+ !File or Directory !Used For !More |}<section end=config /><blockquote>See also...")
 
No edit summary
Line 1: Line 1:
{{Stub}}
{{Stub}}
Each domain in Sympl can have it's own [[crontab]] to run specific tasks. This is configured the same as the normal system crontab, and is kept in <code>/srv/'''''example.com'''''/config/crontab</code> in order to keep tasks associated with domains.
== Scheduling Tasks ==
The Sympl crontab works similarly to the normal system crontab, however the only environment variables which can be set are <code>PATH</code> and <code>MAILTO</code>.
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 (<code>#</code>) and must be on a line by themselves.
<code>'''''minute hour day month day_of_week'''''  command_to_run</code>
{| class="wikitable"
!Field
!Allowed values
|-
|<code>'''''minute'''''</code>
|<code>*</code> <code>0</code>-<code>59</code> <code>,</code> <code>-</code> <code>/</code>
|-
|<code>'''''hour'''''</code>
|<code>*</code> <code>0</code>-<code>23</code> <code>,</code> <code>-</code> <code>/</code>
|-
|<code>'''''day'''''</code>
|<code>*</code> <code>1</code>-<code>31</code> <code>,</code> <code>-</code>
|-
|<code>'''''month'''''</code>
|<code>*</code> <code>1</code>-<code>12</code> or <code>JAN</code>-<code>DEC</code> <code>,</code> <code>-</code>
|-
|<code>'''''day_of_week'''''</code>
|<code>*</code> <code>0</code>-<code>6</code> or <code>SUN</code>-<code>SAT</code> <code>,</code> <code>-</code>
|}
Commas (<code>,</code>) are used to separate items in lists, and hyphens (<code>-</code>) are ranges.
The slash (<code>/</code>) is preceded by an asterisk (<code>*</code>) and followed by a number which indicates the job should run if the minute or hour is divisible by the number, for example a <code>'''''minuite'''''</code> value of <code>*/5</code> will run the task every <code>5</code> minutes.
=== Time Shortcuts ===
There are a number of shortcuts for common times for tasks to run, which replaces the five values above.
<code>'''''@shortcut'''''  command_to_run</code>
{| class="wikitable"
!Shortcut
!Tasks will Run
|-
|<code>@hourly</code>
|Every hour on the hour.
|-
|<code>@daily</code> or <code>@midnight</code>
|Every day at midnight.
|-
|<code>@weekly</code>
|Once a week on Sunday.
|-
|<code>@monthly</code>
|Each month on the 1st at midnight.
|-
|<code>@yearly</code> or <code>@annually</code>
|Midnight at Jan 1st each year
|}
Note that there is no <code>@reboot</code> 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!"
<br />
== Testing Configuration ==
Sympl includes a parser which allows you to check the next run-time of the tasks. Run <code>sympl-crontab --test /srv/'''''example.com'''''/config/crontab</code> to get a list of the configured tasks, and their next run-time.
==Configuration Reference==
==Configuration Reference==
<section begin=config />
<section begin=config />

Revision as of 11:45, 19 July 2019

This article is a Stub. You can help the Sympl Project by expanding it.

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

Scheduling Tasks

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.

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 tasks to run, which replaces the five values above.

@shortcut command_to_run

Shortcut Tasks 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 tasks. Run sympl-crontab --test /srv/example.com/config/crontab to get a list of the configured tasks, and their next run-time.

Configuration Reference

File or Directory Used For More

See also Configuration Reference for other configuration files.