From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:41429) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iakhV-0006XC-LV for guix-patches@gnu.org; Fri, 29 Nov 2019 13:09:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iakhS-0006Gz-98 for guix-patches@gnu.org; Fri, 29 Nov 2019 13:09:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:55810) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iakhS-0006GL-4k for guix-patches@gnu.org; Fri, 29 Nov 2019 13:09:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iakhS-0007T7-0U for guix-patches@gnu.org; Fri, 29 Nov 2019 13:09:02 -0500 Subject: [bug#38429] [PATCH] Add scron service. References: <20191129175356.12403-1-rob@vllmrt.net> In-Reply-To: <20191129175356.12403-1-rob@vllmrt.net> Resent-Message-ID: From: Robert Vollmert Date: Fri, 29 Nov 2019 19:07:22 +0100 Message-Id: <20191129180721.13923-1-rob@vllmrt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 38429@debbugs.gnu.org Cc: Robert Vollmert 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 +;;; +;;; 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 . + +(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 + make-scron-configuration + scron-configuration? + (scron scron-configuration-scron ;package + (default scron)) + (jobs scron-configuration-jobs ;list of + (default '()))) + +(define-record-type* 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 + (($ schedule command) + (list schedule " " command "\n"))) + jobs)))) + +(define scron-shepherd-services + (match-lambda + (($ 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