From: Robert Vollmert <rob@vllmrt.net>
To: 38429@debbugs.gnu.org
Cc: Robert Vollmert <rob@vllmrt.net>
Subject: [bug#38429] [PATCH] Add scron service.
Date: Fri, 29 Nov 2019 19:07:22 +0100 [thread overview]
Message-ID: <20191129180721.13923-1-rob@vllmrt.net> (raw)
In-Reply-To: <20191129175356.12403-1-rob@vllmrt.net>
It's a simple replacement for the mcron service.
If you have a mcron job definition like
(define cron-job
#~(job "*/15 * * * *" #$(program-file ...)))
you can convert it into the valid scron job
(define cron-job
(scron-job (schedule "/15 * * * *")
(program-file ...)))
* gnu/services/scron.scm: New file.
* gnu/local.mk: Add it.
---
Sent an incomplete patch before, this is the full version.
gnu/local.mk | 1 +
gnu/services/scron.scm | 101 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 102 insertions(+)
create mode 100644 gnu/services/scron.scm
diff --git a/gnu/local.mk b/gnu/local.mk
index 56ff1d0f7b..ca8b6ecc1b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -552,6 +552,7 @@ GNU_SYSTEM_MODULES = \
%D%/services/nix.scm \
%D%/services/nfs.scm \
%D%/services/pam-mount.scm \
+ %D%/services/scron.scm \
%D%/services/security-token.scm \
%D%/services/shepherd.scm \
%D%/services/sound.scm \
diff --git a/gnu/services/scron.scm b/gnu/services/scron.scm
new file mode 100644
index 0000000000..0ea7cc9698
--- /dev/null
+++ b/gnu/services/scron.scm
@@ -0,0 +1,101 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
+;;;
+;;; 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 scron)
+ #:use-module (gnu services)
+ #:use-module (gnu services shepherd)
+ #:autoload (gnu packages suckless) (scron)
+ #:use-module (guix gexp)
+ #:use-module (guix records)
+ #:use-module (guix store)
+ #:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
+ #:export (scron-configuration
+ scron-configuration?
+ scron-configuration-scron
+ scron-configuration-jobs
+
+ scron-job
+ scron-job?
+ scron-job-schedule
+ scron-job-command
+
+ scron-service-type
+ scron-service))
+
+;;; Commentary:
+;;;
+;;; This module implements a service to run instances of scron, a
+;;; periodic job execution daemon. Example of a service:
+;;
+;; (service scron-service-type
+;; (scron-configuration
+;; (jobs (list (scron-job (schedule "*/15 * * * *")
+;; (command "echo hello!"))))))
+;;;
+;;; Code:
+
+(define-record-type* <scron-configuration> scron-configuration
+ make-scron-configuration
+ scron-configuration?
+ (scron scron-configuration-scron ;package
+ (default scron))
+ (jobs scron-configuration-jobs ;list of <scron-job>
+ (default '())))
+
+(define-record-type* <scron-job> scron-job
+ make-scron-job
+ scron-job?
+ (schedule scron-job-schedule (default "* * * * *"))
+ (command scron-job-command (default '())))
+
+(define (crontab jobs)
+ (apply mixed-text-file "crontab"
+ (concatenate
+ (map
+ (match-lambda
+ (($ <scron-job> schedule command)
+ (list schedule " " command "\n")))
+ jobs))))
+
+(define scron-shepherd-services
+ (match-lambda
+ (($ <scron-configuration> scron jobs)
+ (list
+ (shepherd-service
+ (provision '(scron))
+ (requirement '(user-processes))
+ (start #~(make-forkexec-constructor
+ (list (string-append #$scron "/bin/crond")
+ "-n" ; don't fork
+ "-f" #$(crontab jobs))
+ #:log-file "/var/log/scron.log"))
+ (stop #~(make-kill-destructor)))))))
+
+(define scron-service-type
+ (service-type (name 'scron)
+ (extensions
+ (list (service-extension shepherd-root-service-type
+ scron-shepherd-services)))
+ (compose concatenate)
+ (extend (lambda (config jobs)
+ (scron-configuration
+ (inherit config)
+ (jobs (append (scron-configuration-jobs config)
+ jobs)))))
+ (default-value (scron-configuration))))
--
2.24.0
next prev parent reply other threads:[~2019-11-29 18:09 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 [this message]
2019-12-02 9:01 ` Ludovic Courtès
2019-12-03 12:46 ` [bug#38429] [PATCH 1/5] document scron Robert Vollmert
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=20191129180721.13923-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).