User:Johannbg/Packaging/CronFiles

From FedoraProject

< User:Johannbg(Difference between revisions)
Jump to: navigation, search
(Cron Job Files Packaging)
(Cron Job file)
Line 19: Line 19:
 
Should we have sample here?
 
Should we have sample here?
  
=== Example of cron job definition ===
+
Example of cron job definition  
 
+
If file needs to be executed on an interval other
+
  
 
<pre>
 
<pre>
Line 32: Line 30:
 
# *  *  *  *  * user-name  command to be executed
 
# *  *  *  *  * user-name  command to be executed
 
</pre>
 
</pre>
 
=== Example minimal logrotate log file with user create mode ===
 
 
<pre>
 
/var/log/example/*log {
 
missingok # If the log file is missing, go on to the next one without issuing an error message
 
notifempty # Don't do any rotation if the logfile is empty
 
compress # Compress older files with gzip
 
  delaycompress # Don't compress yesterdays files
 
create 640 owner group  # Set create mode immediately after rotation
 
}
 
</pre>
 
 
=== Example minimal logrotate file with daemon restart ===
 
 
<pre>
 
/var/log/example/*log {
 
missingok # If the log file is missing, go on to the next one without issuing an error message
 
notifempty # Don't do any rotation if the logfile is empty
 
compress # Compress older files with gzip
 
  delaycompress # Don't compress yesterdays files
 
sharedscripts # Scripts are only run once for all files in directory
 
postrotate
 
/usr/bin/systemctl restart example.service 2>/dev/null || true
 
endscript
 
}
 
</pre>
 
 
=== Example minimal logrotate file with user create mode and daemon restart ===
 
 
<pre>
 
/var/log/example/*log {
 
missingok # If the log file is missing, go on to the next one without issuing an error message
 
notifempty # Don't do any rotation if the logfile is empty
 
compress # Compress older files with gzip
 
  delaycompress # Don't compress yesterdays files
 
create 640 owner group  # Set create mode immediately after rotation
 
sharedscripts # Scripts are only run once for all files in directory
 
postrotate
 
/usr/bin/systemctl restart example.service 2>/dev/null || true
 
endscript
 
}
 
</pre>
 
 
{{admon/tip|Debugging logrotate file|You can debug your logrotate file by running
 
<pre># logrotate -d -f /etc/logrotate.d/example.conf</pre>from the command line.}}
 
  
 
== Cron job file names ==
 
== Cron job file names ==

Revision as of 21:21, 19 March 2013

Contents

Fedora Cron Job Files

This document describes the guidelines for packaging cron job file(s), in Fedora.

For the purposes of these guidelines, a cron job file is defined as an script (e.g., shell scripts or Perl scripts).

If your package requires regularly scheduled tasks to operate properly and does not ship systemd unit file, you can use those files to set that up.

Cron Job Files on the filesystem

Packages with cron job files must be placed respectfully 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.

If a certain cron job has to be executed at some frequency or at a specific time interval other then the above, that cron job file should be placed in /etc/cron.d directory.

All 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.

Cron Job file

Should we have sample here?

Example of cron job definition

# .---------------- 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

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 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.

Cron Job Files Packaging

If an package is going to provide cron job file(s) then it must be placed into a separate $name-cron subpackage.

The file name of a cron job file should match the name of the package from which it comes and the it must depend on crontab package.

Example of cron job subpackage

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

%package example-cron
Summary:  Cron job file for %{name}
Group:    System Environment/Base
Requires: %{name} = %{version}-%{release}
Requires: crontab

%description example-cron
Cron job file for %{name}

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

%files example-cron
%config(noreplace) %{_sysconfdir}/cron.daily/%{name}