Packaging:CronFiles

From FedoraProject

(Difference between revisions)
Jump to: navigation, search
(Writeup of https://fedorahosted.org/fpc/ticket/324 (finally))
 
(2 intermediate revisions by one user not shown)
Line 7: Line 7:
 
== Cron Job Files on the filesystem ==
 
== Cron Job Files on the filesystem ==
  
Packages with cron job files must be placed into one or more of the following directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly depending on the intended interval they should run.
+
Packages with cron job files must place those cron job files into one or more of the following directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly depending on the intended interval they should run.
  
 
There is an exception to this rule:
 
There is an exception to this rule:
 
If a certain cron job has to be executed at some frequency or at a specific time interval other than the above, then a custom crontab file should be added to /etc/cron.d (with 0640 permissions). In this case, the cron job file (the script) must be placed in an appropriate system location (e.g. %{_sbindir}, %{_libexecdir}), and NOT in /etc/cron.d.
 
If a certain cron job has to be executed at some frequency or at a specific time interval other than the above, then a custom crontab file should be added to /etc/cron.d (with 0640 permissions). In this case, the cron job file (the script) must be placed in an appropriate system location (e.g. %{_sbindir}, %{_libexecdir}), and NOT in /etc/cron.d.
  
All cron job files installed in any of these directories must be scripts and must be treated as configuration files so that they can easily be modified by the local system administrator.
+
Both cron job files and crontab definition files installed in any of these directories must be treated as configuration files so that they can easily be modified by the local system administrator.
  
 
== Cron Job file ==
 
== Cron Job file ==
Line 47: Line 47:
 
The file name of a cron job file should match the name of the package from which it comes.
 
The file name of a cron job file should match the name of the package from which it comes.
  
If a package supplies multiple cron job files files in the same directory, the file names should all start with the name of the package by a hyphen (-) and a suitable suffix.
+
If a package supplies multiple cron job files files in the same directory, the file names should all start with the name of the package followed by a hyphen (-) and a suitable suffix.
  
 
{{admon/tip|A cron job file name cannot include any period or plus characters as this will cause cron to ignore the file. Underscores should be used instead.}}
 
{{admon/tip|A cron job file name cannot include any period or plus characters as this will cause cron to ignore the file. Underscores should be used instead.}}
Line 54: Line 54:
  
 
Cron job file(s) in packages must be marked as %config(noreplace), and their filename(s) should match the name of the package.
 
Cron job file(s) in packages must be marked as %config(noreplace), and their filename(s) should match the name of the package.
 +
 +
Helper files used by cron job files should be placed in appropriate system locations (e.g. %{_bindir} or %{_libexecdir}) and do not need to be marked as %config.
  
 
Packages with cron job files must have an explicit <code>Requires: crontabs</code>.  Since <code>crontabs</code> requires <code>/etc/cron.d</code> and all cron daemon packages create (and own) that directory, <code>crontabs</code> serves as a virtual requires for cron daemon functionality.
 
Packages with cron job files must have an explicit <code>Requires: crontabs</code>.  Since <code>crontabs</code> requires <code>/etc/cron.d</code> and all cron daemon packages create (and own) that directory, <code>crontabs</code> serves as a virtual requires for cron daemon functionality.
Line 75: Line 77:
 
%config(noreplace) %{_sysconfdir}/cron.monthly/%{name}
 
%config(noreplace) %{_sysconfdir}/cron.monthly/%{name}
 
</pre>
 
</pre>
 +
 +
[[Category:Packaging guidelines]]

Latest revision as of 19:50, 11 December 2014

Contents

[edit] Fedora Cron Job Files

This document describes the guidelines for packaging cron job files in Fedora.

For the purposes of these guidelines, a cron job file is defined as a script (e.g., a shell script or a Perl script). These cron job files are scheduled to run on regular intervals by a cron daemon.

[edit] Cron Job Files on the filesystem

Packages with cron job files must place those cron job files into one or more of the following directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly depending on the intended interval they should run.

There is an exception to this rule: If a certain cron job has to be executed at some frequency or at a specific time interval other than the above, then a custom crontab file should be added to /etc/cron.d (with 0640 permissions). In this case, the cron job file (the script) must be placed in an appropriate system location (e.g. %{_sbindir}, %{_libexecdir}), and NOT in /etc/cron.d.

Both cron job files and crontab definition files installed in any of these directories must be treated as configuration files so that they can easily be modified by the local system administrator.

[edit] Cron Job file

An typical cron job file is just an script like

#!/bin/sh
# My cron job script
# set -x

echo "This is my simple cron job script"

exit 0

Example of crontab definition run at ever other hour specified in /etc/cron.d/example

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

0 */2 * * * root /usr/sbin/example

[edit] Cron job file names

The file name of a cron job file should match the name of the package from which it comes.

If a package supplies multiple cron job files files in the same directory, the file names should all start with the name of the package followed by a hyphen (-) and a suitable suffix.

Idea.png
A cron job file name cannot include any period or plus characters as this will cause cron to ignore the file. Underscores should be used instead.

[edit] Cron Job Files Packaging

Cron job file(s) in packages must be marked as %config(noreplace), and their filename(s) should match the name of the package.

Helper files used by cron job files should be placed in appropriate system locations (e.g. %{_bindir} or %{_libexecdir}) and do not need to be marked as %config.

Packages with cron job files must have an explicit Requires: crontabs. Since crontabs requires /etc/cron.d and all cron daemon packages create (and own) that directory, crontabs serves as a virtual requires for cron daemon functionality.

[edit] Example of cron job packaging

Name:
.....
Source1: %{name}.cron
Requires: crontabs

.....

%install 
.....
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/cron.monthly
%{__install} -p -D -m 0750 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/cron.monthly/%{name}

%files
%config(noreplace) %{_sysconfdir}/cron.monthly/%{name}