summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-06-26 15:27:34 +0200
committerLudovic Courtès <ludo@gnu.org>2016-06-26 15:29:32 +0200
commit8ac6282c4b97ece43b922a8c1a99a0a8e753c765 (patch)
tree3c85f2b1e9705698aa46bb8d147d26a12b1ea88d /doc
parentc9a03e65b8558d10669cc5a844cd1f83f3651828 (diff)
doc: Augment mcron example.
Suggested by Danny Milosavljevic. * doc/guix.texi (Scheduled Job Execution): Add unprivileged job example, and show the use of thunks as job actions and gexps.
Diffstat (limited to 'doc')
-rw-r--r--doc/guix.texi28
1 files changed, 23 insertions, 5 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 9e3806c845c..7204f2e9392 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -7507,27 +7507,45 @@ Unix @command{cron} daemon; the main difference is that it is
7507implemented in Guile Scheme, which provides a lot of flexibility when 7507implemented in Guile Scheme, which provides a lot of flexibility when
7508specifying the scheduling of jobs and their actions. 7508specifying the scheduling of jobs and their actions.
7509 7509
7510For example, to define an operating system that runs the 7510The example below defines an operating system that runs the
7511@command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files}) 7511@command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
7512and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily: 7512and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
7513well as the @command{mkid} command on behalf of an unprivileged user
7514(@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
7515gexps to introduce job definitions that are passed to mcron
7516(@pxref{G-Expressions}).
7513 7517
7514@lisp 7518@lisp
7515(use-modules (guix) (gnu) (gnu services mcron)) 7519(use-modules (guix) (gnu) (gnu services mcron))
7520(use-package-modules base idutils)
7516 7521
7517(define updatedb-job 7522(define updatedb-job
7518 ;; Run 'updatedb' at 3 AM every day. 7523 ;; Run 'updatedb' at 3AM every day. Here we write the
7524 ;; job's action as a Scheme procedure.
7519 #~(job '(next-hour '(3)) 7525 #~(job '(next-hour '(3))
7520 "updatedb --prunepaths='/tmp /var/tmp /gnu/store'")) 7526 (lambda ()
7527 (execl (string-append #$findutils "/bin/updatedb")
7528 "updatedb"
7529 "--prunepaths=/tmp /var/tmp /gnu/store"))))
7521 7530
7522(define garbage-collector-job 7531(define garbage-collector-job
7523 ;; Collect garbage 5 minutes after midnight every day. 7532 ;; Collect garbage 5 minutes after midnight every day.
7533 ;; The job's action is a shell command.
7524 #~(job "5 0 * * *" ;Vixie cron syntax 7534 #~(job "5 0 * * *" ;Vixie cron syntax
7525 "guix gc -F 1G")) 7535 "guix gc -F 1G"))
7526 7536
7537(define idutils-jobs
7538 ;; Update the index database as user "charlie" at 12:15PM
7539 ;; and 19:15PM. This runs from the user's home directory.
7540 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
7541 (string-append #$idutils "/bin/mkid src")
7542 #:user "charlie"))
7543
7527(operating-system 7544(operating-system
7528 ;; @dots{} 7545 ;; @dots{}
7529 (services (cons (mcron-service (list garbage-collector-job 7546 (services (cons (mcron-service (list garbage-collector-job
7530 updatedb-job)) 7547 updatedb-job
7548 idutils-job))
7531 %base-services))) 7549 %base-services)))
7532@end lisp 7550@end lisp
7533 7551