unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Vollmert <rob@vllmrt.net>
To: 38429@debbugs.gnu.org
Cc: Robert Vollmert <rob@vllmrt.net>
Subject: [bug#38429] [PATCH 1/5] document scron
Date: Tue,  3 Dec 2019 13:46:29 +0100	[thread overview]
Message-ID: <20191203124632.1987-1-rob@vllmrt.net> (raw)
In-Reply-To: <20191129175356.12403-1-rob@vllmrt.net>

* doc/guix.texi: Add documentation for scron-service.
---

The first in a series of supplementary patches on top of the base scron
service patch, to be squashed into that commit.

 doc/guix.texi | 100 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index e0b831c7e8..1aafa01166 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -283,7 +283,7 @@ System Configuration
 Services
 
 * Base Services::               Essential system services.
-* Scheduled Job Execution::     The mcron service.
+* Scheduled Job Execution::     Cron services.
 * Log Rotation::                The rottlog service.
 * Networking Services::         Network setup, SSH daemon, etc.
 * X Window::                    Graphical display.
@@ -12890,6 +12890,104 @@ specifications,, mcron, GNU@tie{}mcron}).
 @end deftp
 
 
+@cindex scron
+@cindex scheduling jobs
+The @code{(gnu services scron)} module provides an interface to
+scron, a simple daemon to run jobs at scheduled times. scron is
+similar to the traditional Unix @command{cron} daemon;
+the main difference is that it is much simpler.
+
+Jobs are executed as root via the shell with working direction @code{/}.
+Use @code{su(1)} or corresponding Guile functions
+(@pxref{Processes,,, guile, GNU Guile Reference Manual}).
+
+The example below defines an operating system that runs the
+@command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
+and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
+well as the @command{mkid} command on behalf of an unprivileged user
+(@pxref{mkid invocation,,, idutils, ID Database Utilities}).
+
+@lisp
+(use-modules (guix) (gnu) (gnu services scron))
+(use-package-modules base idutils)
+
+(define updatedb-job
+  ;; Run 'updatedb' at 3AM every day.  Here we write the
+  ;; job's action as a Scheme procedure.
+  (let*
+    ((exp #~(begin
+              (execl (string-append #$findutils "/bin/updatedb")
+                     "updatedb"
+                     "--prunepaths=/tmp /var/tmp /gnu/store")))
+     (script (program-file "updatedb-job" exp))
+    (scron-job
+      (schedule "0 3 * * *")
+      (command  script))))
+
+(define garbage-collector-job
+  ;; Collect garbage 5 minutes after midnight every day.
+  ;; The job's action is a shell command.
+  (scron-job
+    (schedule "5 0 * * *")
+    (command  "guix gc -F 1G")))
+
+(define idutils-job
+  ;; Update the index database as user "charlie" at 12:15PM
+  ;; and 19:15PM.  This runs from the user's home directory.
+  (let*
+    ((cmd      #~(string-append #$idutils "/bin/mkid src"))
+     (cmd-su   #~(string-append "su -c '" #$cmd "' charlie")))
+    (scron-job
+      (schedule "15 12,19 * * *")
+      (command  cmd-su))))
+
+(operating-system
+  ;; @dots{}
+  (services (cons (service scron-service-type
+                           (scron-configuration
+                            (jobs (list garbage-collector-job
+                                        updatedb-job
+                                        idutils-job))))
+                  %base-services)))
+@end lisp
+
+@defvr {Scheme Variable} scron-service-type
+
+This is the type of the @code{scron} service, whose value is an
+@code{scron-configuration} object.
+
+This service type can be the target of a service extension that provides
+it additional job specifications (@pxref{Service Composition}).  In
+other words, it is possible to define services that provide additional
+mcron jobs to run.
+@end defvr
+
+@deftp {Data Type} scron-configuration
+Data type representing the configuration of scron.
+
+@table @asis
+@item @code{scron} (default: @var{scron})
+The scron package to use.
+
+@item @code{jobs}
+This is a list of scron jobs.
+@end table
+@end deftp
+
+@deftp {Data Type} scron-job
+Data type representing an scron job.
+
+@table @asis
+@item @code{schedule}
+The job schedule, in Vixie cron syntax. See the @code{scron(1)}
+man page for more information.
+
+@item @code{command}
+The shell command to run, as a value that lowers to a string.
+@end table
+@end deftp
+
+
 @node Log Rotation
 @subsection Log Rotation
 
-- 
2.24.0

  parent reply	other threads:[~2019-12-03 12:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29 17:53 [bug#38429] [PATCH] Add scron service Robert Vollmert
2019-11-29 18:07 ` Robert Vollmert
2019-12-02  9:01   ` Ludovic Courtès
2019-12-03 12:46 ` Robert Vollmert [this message]
2019-12-03 12:46   ` [bug#38429] [PATCH 2/5] scron-service: remove job defaults Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 3/5] scron: Add description Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 4/5] scron: add system test Robert Vollmert
2019-12-03 12:50     ` Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 5/5] gnu/services: Add description to mcron-service-type Robert Vollmert
2019-12-07 23:32   ` [bug#38429] [PATCH 1/5] document scron Ludovic Courtès
2019-12-07 23:43     ` Robert Vollmert
2019-12-07 23:46       ` bug#38429: " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191203124632.1987-1-rob@vllmrt.net \
    --to=rob@vllmrt.net \
    --cc=38429@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).