Next: , Previous: , Up: Services   [Contents][Index]


6.2.7.2 Scheduled Job Execution

The (gnu services mcron) module provides an interface to GNU mcron, a daemon to run jobs at scheduled times (see GNU mcron). GNU mcron is similar to the traditional Unix cron daemon; the main difference is that it is implemented in Guile Scheme, which provides a lot of flexibility when specifying the scheduling of jobs and their actions.

The example below defines an operating system that runs the updatedb (see Invoking updatedb in Finding Files) and the guix gc commands (see Invoking guix gc) daily, as well as the mkid command on behalf of an unprivileged user (see mkid invocation in ID Database Utilities). It uses gexps to introduce job definitions that are passed to mcron (see G-Expressions).

(use-modules (guix) (gnu) (gnu services mcron))
(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.
  #~(job '(next-hour '(3))
         (lambda ()
           (execl (string-append #$findutils "/bin/updatedb")
                  "updatedb"
                  "--prunepaths=/tmp /var/tmp /gnu/store"))))

(define garbage-collector-job
  ;; Collect garbage 5 minutes after midnight every day.
  ;; The job's action is a shell command.
  #~(job "5 0 * * *"            ;Vixie cron syntax
         "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.
  #~(job '(next-minute-from (next-hour '(12 19)) '(15))
         (string-append #$idutils "/bin/mkid src")
         #:user "charlie"))

(operating-system
  ;; …
  (services (cons (mcron-service (list garbage-collector-job
                                       updatedb-job
                                       idutils-job))
                  %base-services)))

See mcron job specifications in GNU mcron, for more information on mcron job specifications. Below is the reference of the mcron service.

Scheme Procedure: mcron-service jobs [#:mcron mcron2]

Return an mcron service running mcron that schedules jobs, a list of gexps denoting mcron job specifications.

This is a shorthand for:

(service mcron-service-type
         (mcron-configuration (mcron mcron) (jobs jobs)))
Scheme Variable: mcron-service-type

This is the type of the mcron service, whose value is an mcron-configuration object.

This service type can be the target of a service extension that provides it additional job specifications (see Service Composition). In other words, it is possible to define services that provide additional mcron jobs to run.

Data Type: mcron-configuration

Data type representing the configuration of mcron.

mcron (default: mcron2)

The mcron package to use.

jobs

This is a list of gexps (see G-Expressions), where each gexp corresponds to an mcron job specification (see mcron job specifications in GNU mcron).


Next: , Previous: , Up: Services   [Contents][Index]