aboutsummaryrefslogtreecommitdiff
path: root/gnu/services/mcron.scm
blob: 5757bf8cf691ea42123f08c05350154f0d8bad20 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu services mcron)
  #:use-module (gnu services)
  #:use-module (gnu services base)
  #:use-module (gnu services shepherd)
  #:autoload   (gnu packages guile) (mcron)
  #:use-module (guix records)
  #:use-module (guix gexp)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match)
  #:use-module (ice-9 vlist)
  #:export (mcron-configuration
            mcron-configuration?
            mcron-configuration-mcron
            mcron-configuration-jobs

            mcron-service-type
            mcron-service))

;;; Commentary:
;;;
;;; This module implements a service that to run instances of GNU mcron, a
;;; periodic job execution daemon.  Example of a service:
;;
;;  (service mcron-service-type
;;           (mcron-configuration
;;            (jobs (list #~(job next-second-from
;;                               (lambda ()
;;                                 (call-with-output-file "/dev/console"
;;                                   (lambda (port)
;;                                     (display "hello!\n" port)))))))))
;;;
;;; Code:

(define-record-type* <mcron-configuration> mcron-configuration
  make-mcron-configuration
  mcron-configuration?
  (mcron             mcron-configuration-mcron    ;package
                     (default mcron))
  (jobs              mcron-configuration-jobs     ;list of <mcron-job>
                     (default '())))

(define (job-file job)
  (scheme-file "mcron-job" job))

(define (shepherd-schedule-action mcron files)
  "Return a Shepherd action that runs MCRON with '--schedule' for the given
files."
  (shepherd-action
   (name 'schedule)
   (documentation
    "Display jobs that are going to be scheduled.")
   (procedure
    #~(lambda* (_ #:optional (n "5"))
        ;; XXX: This is a global side effect.
        (setenv "GUILE_AUTO_COMPILE" "0")

        ;; Run 'mcron' in a pipe so we can explicitly redirect its output to
        ;; 'current-output-port', which at this stage is bound to the client
        ;; connection.
        (let ((pipe (open-pipe* OPEN_READ
                                #$(file-append mcron "/bin/mcron")
                                (string-append "--schedule=" n)
                                #$@files)))
          (let loop ()
            (match (read-line pipe 'concat)
              ((? eof-object?)
               (catch 'system-error
                 (lambda ()
                   (zero? (close-pipe pipe)))
                 (lambda args
                   ;; There's with race between the SIGCHLD handler, which
                   ;; could call 'waitpid' before 'close-pipe' above does.  If
                   ;; we get ECHILD, that means we lost the race, but that's
                   ;; fine.
                   (or (= ECHILD (system-error-errno args))
                       (apply throw args)))))
              (line
               (display line)
               (loop)))))))))

(define mcron-shepherd-services
  (match-lambda
    (($ <mcron-configuration> mcron ())           ;nothing to do!
     '())
    (($ <mcron-configuration> mcron jobs)
     (let ((files (map job-file jobs)))
       (list (shepherd-service
              (provision '(mcron))
              (requirement '(user-processes))
              (modules `((srfi srfi-1)
                         (srfi srfi-26)
                         (ice-9 popen)            ;for the 'schedule' action
                         (ice-9 rdelim)
                         (ice-9 match)
                         ,@%default-modules))
              (start #~(make-forkexec-constructor
                        (list (string-append #$mcron "/bin/mcron") #$@files)

                        ;; Disable auto-compilation of the job files and set a
                        ;; sane value for 'PATH'.
                        #:environment-variables
                        (cons* "GUILE_AUTO_COMPILE=0"
                               "PATH=/run/current-system/profile/bin"
                               (remove (cut string-prefix? "PATH=" <>)
                                       (environ)))))
              (stop #~(make-kill-destructor))

              (actions
               (list (shepherd-schedule-action mcron files)))))))))

(define mcron-service-type
  (service-type (name 'mcron)
                (extensions
                 (list (service-extension shepherd-root-service-type
                                          mcron-shepherd-services)
                       (service-extension profile-service-type
                                          (compose list
                                                   mcron-configuration-mcron))))
                (compose concatenate)
                (extend (lambda (config jobs)
                          (mcron-configuration
                           (inherit config)
                           (jobs (append (mcron-configuration-jobs config)
                                         jobs)))))
                (default-value (mcron-configuration)))) ;empty job list

(define* (mcron-service jobs #:optional (mcron mcron))
  "Return an mcron service running @var{mcron} that schedules @var{jobs}, a
list of gexps denoting mcron job specifications.

This is a shorthand for:
@example
  (service mcron-service-type
           (mcron-configuration (mcron mcron) (jobs jobs)))
@end example
"
  (service mcron-service-type
           (mcron-configuration (mcron mcron) (jobs jobs))))

;;; mcron.scm ends here
): Same. * gnu/packages/machine-learning.scm (dlib): Same. * gnu/packages/maths.scm (lapack, superlu, z3): Same. * gnu/packages/password-utils.scm (keepassxc): Same. * gnu/packages/photo.scm (darktable): Same. * gnu/packages/rdesktop.scm (freerdp): Same. Efraim Flashner 2017-11-19Merge branch 'master' into core-updatesMarius Bakke 2017-11-18gnu: Move date/time packages from python.scm to time.scm....* gnu/packages/python.scm (python-pytz, python2-pytz, python-dateutil, python2-dateutil, python-parsedatetime, python2-parsedatetime, python-tzlocal, python-isodate, python2-isodate, python-iso8601, python2-iso8601, python-monotonic, python2-monotonic, python-pyrfc3339, python2-pyrfc3339, python-arrow, python2-arrow, python-aniso8601, python2-aniso8601): Move from here... * gnu/packages/time.scm: ...to here. * gnu/packages/calendar.scm, gnu/packages/check.scm, gnu/packages/django.scm, gnu/packages/ebook.scm, gnu/packages/gnome.scm, gnu/packages/irc.scm, gnu/packages/jrnl.scm, gnu/packages/mail.scm, gnu/packages/openstack.scm, gnu/packages/package-management.scm, gnu/packages/python-crypto.scm, gnu/packages/python-web.scm, gnu/packages/rdf.scm, gnu/packages/statistics.scm, gnu/packages/tls.scm, gnu/packages/tryton.scm, gnu/packages/version-control.scm: Adjust accordingly. Ricardo Wurmus 2017-11-17gnu: Move testing packages from python.scm to check.scm....* gnu/packages/python.scm (python-behave-web-api, python2-behave-web-api, python-mock, python2-mock, python-mock-2, python-nose, python2-nose, python-nose2, python2-nose2, python-unittest2, python2-unittest2, python-pytest, python2-pytest, python-pytest-3.0, python2-pytest-3.0, python-pytest-cov, python2-pytest-cov, python-pytest-runner, python2-pytest-runner, python-pytest-mock, python2-pytest-mock, python-pytest-xdist, python2-pytest-xdist, python-scripttest, python2-scripttest, python-testtools, python2-testtools, python-testscenarios, python2-testscenarios, python-testresources, python2-testresources, python-subunit, python2-subunit, python-fixtures, python2-fixtures, python-testrepository, python2-testrepository, python-coverage, python2-coverage, python-cov-core, python2-cov-core, python-testpath, python2-testpath, python-testlib, python2-testlib, python-pytest-cache, python2-pytest-cache, python-pytest-localserver, python-pytest-xprocess, python-pytest-subtesthack, python2-pytest-subtesthack, python-hypothesis, python2-hypothesis, python-lit, python2-lit, python-pytest-pep8, python2-pytest-pep8, python-pytest-flakes, python2-pytest-flakes, python2-coverage-test-runner, python-pylint, python2-pylint, python-paramunittest, python2-python-paramunittest, python-pytest-warnings, python2-pytest-warnings, python-pytest-capturelog, python2-pytest-capturelog, python-pytest-catchlog, python2-pytest-catchlog, python-nosexcover, python2-nosexcover, python-discover, python2-discover, behave, python-rednose, python2-rednose, python-nose-randomly, python2-nose-randomly, python-nose-timer, python2-nose-timer): Move from here... * gnu/packages/check.scm: ...to here. * gnu/packages/admin.scm, gnu/packages/android.scm, gnu/packages/backup.scm, gnu/packages/bioinformatics.scm, gnu/packages/calendar.scm, gnu/packages/dav.scm, gnu/packages/django.scm, gnu/packages/freedesktop.scm, gnu/packages/haskell.scm, gnu/packages/image.scm, gnu/packages/irc.scm, gnu/packages/jrnl.scm, gnu/packages/ldc.scm, gnu/packages/libffi.scm, gnu/packages/mail.scm, gnu/packages/mpd.scm, gnu/packages/openstack.scm, gnu/packages/package-management.scm, gnu/packages/password-utils.scm, gnu/packages/python-crypto.scm, gnu/packages/python-web.scm, gnu/packages/rdf.scm, gnu/packages/statistics.scm, gnu/packages/storage.scm, gnu/packages/time.scm, gnu/packages/tls.scm, gnu/packages/tor.scm, gnu/packages/tryton.scm: Adjust accordingly. Ricardo Wurmus 2017-10-19gnu: Remove python-pytest@2....* gnu/packages/python.scm (python-pytest): Update to 3.0.7. [source]: Move substitution to ... [arguments]: ... here. Incorporate phase from pytest-3.0. [native-inputs]: Add PYTHON-HYPOTHESIS. (python-pytest-3.0): Remove variable. (python2-pytest-3.0): Rename to ... (python2-pytest): ... this. [native-inputs]: Add PYTHON2-ENUM34. * gnu/packages/backup.scm (borg)[native-inputs]: Replace PYTHON-PYTEST-3.0 with PYTHON-PYTEST. * gnu/packages/calendar.scm (khal): Likewise. * gnu/packages/databases.scm (python-orator): Likewise. * gnu/packages/python.scm (python-sphinx-1.6, python-sphinx-1.5.3, python-pexpect, python-cryptography, python-pyopenssl, python-pytest-warnings, python-pytest-capturelog, python-pytest-catchlog, python-marshmallow, python-apispec, python-flasgger, python-pyjwt, python-grako, python-honcho): Likewise. * gnu/packages/web.scm (python-internetarchive): Likewise. Marius Bakke 2017-10-07gnu: khal: Update to 0.9.8....* gnu/packages/calendar.scm (khal): Update to 0.9.8. [arguments]: Make sure to stop building if the documentation fails to build. Skip some failing tests. Leo Famulari 2017-09-28gnu: libical: Fix libdir install path....Reported by sadiq on IRC. * gnu/packages/calendar.scm (libical)[arguments]: Remove configure flag adding /lib64 to rpath, add flag to force libdir to /lib. Efraim Flashner 2017-08-29Update e-mail for Kei Kebreau....* .mailmap: Map kei@openmailbox.org to current address. * gnu/local.mk: Replace kei@openmailbox.org to current address. * gnu/packages/backup.scm: Likewise. * gnu/packages/calendar.scm: Likewise. * gnu/packages/check.scm: Likewise. * gnu/packages/compression.scm: Likewise. * gnu/packages/documentation.scm: Likewise. * gnu/packages/emacs.scm: Likewise. * gnu/packages/fltk.scm: Likewise. * gnu/packages/freedesktop.scm: Likewise. * gnu/packages/game-development.scm: Likewise. * gnu/packages/games.scm: Likewise. * gnu/packages/gnome.scm: Likewise. * gnu/packages/gnustep.scm: Likewise. * gnu/packages/gtk.scm: Likewise. * gnu/packages/hexedit.scm: Likewise. * gnu/packages/image.scm: Likewise. * gnu/packages/maths.scm: Likewise. * gnu/packages/music.scm: Likewise. * gnu/packages/xfce.scm: Likewise. * gnu/packages/python.scm: Likewise. * gnu/packages/tcl.scm: Likewise. * gnu/packages/textutils.scm: Likewise. * gnu/packages/video.scm: Likewise. * gnu/packages/w3m.scm: Likewise. * gnu/packages/web.scm: Likewise. * gnu/packages/web-browsers.scm: Likewise. * gnu/packages/patches/wmfire-update-for-new-gdk-versions.patch: Likewise. Kei Kebreau 2017-08-06gnu: khal: Don't propagate vdirsyncer....* gnu/packages/calendar.scm (khal)[propagated-inputs]: Move vdirsyncer ... [native-inputs]: ... here. Leo Famulari