From a33652ee336ae9a5d2ab5fd54bf2397caec42a0e Mon Sep 17 00:00:00 2001 From: Gábor Boskovits Date: Mon, 18 Jun 2018 12:43:42 +0200 Subject: services: Add prometheus-node-exporter-service-type. * gnu/services/monitoring.scm (prometheus-node-exporter-service-type): New variable. (): New record type. (prometheus-node-exporter-shepherd-service): New procedure. * gnu/doc/guix.texi (Monitoring Services): Document it. * gnu/tests/monitoring.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add test module. --- gnu/services/monitoring.scm | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'gnu/services') diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm index 49a65db4b5..aa3b63a0e4 100644 --- a/gnu/services/monitoring.scm +++ b/gnu/services/monitoring.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Sou Bunnbu +;;; Copyright © 2018 Gábor Boskovits ;;; ;;; This file is part of GNU Guix. ;;; @@ -26,7 +27,9 @@ #:use-module (guix records) #:use-module (ice-9 match) #:export (darkstat-configuration - darkstat-service-type)) + prometheus-node-exporter-configuration + darkstat-service-type + prometheus-node-exporter-service-type)) ;;; @@ -89,3 +92,36 @@ HTTP.") (const %darkstat-accounts)) (service-extension shepherd-root-service-type (compose list darkstat-shepherd-service)))))) + +(define-record-type* + prometheus-node-exporter-configuration + make-prometheus-node-exporter-configuration + prometheus-node-exporter-configuration? + (package prometheus-node-exporter-configuration-package + (default go-github-com-prometheus-node-exporter)) + (web-listen-address prometheus-node-exporter-web-listen-address + (default ":9100"))) + +(define prometheus-node-exporter-shepherd-service + (match-lambda + (( $ + package web-listen-address) + (shepherd-service + (documentation "Prometheus node exporter.") + (provision '(prometheus-node-exporter)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/bin/node_exporter") + "--web.listen-address" #$web-listen-address))) + (stop #~(make-kill-destructor)))))) + +(define prometheus-node-exporter-service-type + (service-type + (name 'prometheus-node-exporter) + (description + "Run @command{node_exporter} to serve hardware and OS metrics to +prometheus.") + (extensions + (list (service-extension + shepherd-root-service-type + (compose list prometheus-node-exporter-shepherd-service)))))) -- cgit 1.4.1 From 701383081a9814d21823d42978ae23ee654e0427 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 11 Jul 2018 23:17:37 +0200 Subject: services: shepherd: Support custom actions. * gnu/services/shepherd.scm ()[actions]: New field. (): New record type. (shepherd-service-file): Pass #:actions to 'make'. * doc/guix.texi (Shepherd Services): Document custom actions. --- doc/guix.texi | 59 +++++++++++++++++++++++++++++++++++++++++++++++ gnu/services/shepherd.scm | 23 +++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) (limited to 'gnu/services') diff --git a/doc/guix.texi b/doc/guix.texi index 8b286e9d8e..34012a357b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -21969,6 +21969,17 @@ Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as G-expressions that get expanded in the Shepherd configuration file (@pxref{G-Expressions}). +@item @code{actions} (default: @code{'()}) +@cindex actions, of Shepherd services +This is a list of @code{shepherd-action} objects (see below) defining +@dfn{actions} supported by the service, in addition to the standard +@code{start} and @code{stop} actions. Actions listed here become available as +@command{herd} sub-commands: + +@example +herd @var{action} @var{service} [@var{arguments}@dots{}] +@end example + @item @code{documentation} A documentation string, as shown when running: @@ -21986,6 +21997,54 @@ This is the list of modules that must be in scope when @code{start} and @end table @end deftp +@deftp {Data Type} shepherd-action +This is the data type that defines additional actions implemented by a +Shepherd service (see above). + +@table @code +@item name +Symbol naming the action. + +@item documentation +This is a documentation string for the action. It can be viewed by running: + +@example +herd doc @var{service} action @var{action} +@end example + +@item procedure +This should be a gexp that evaluates to a procedure of at least one argument, +which is the ``running value'' of the service (@pxref{Slots of services,,, +shepherd, The GNU Shepherd Manual}). +@end table + +The following example defines an action called @code{say-hello} that kindly +greets the user: + +@example +(shepherd-action + (name 'say-hello) + (documentation "Say hi!") + (procedure #~(lambda (running . args) + (format #t "Hello, friend! arguments: ~s\n" + args) + #t))) +@end example + +Assuming this action is added to the @code{example} service, then you can do: + +@example +# herd say-hello example +Hello, friend! arguments: () +# herd say-hello example a b c +Hello, friend! arguments: ("a" "b" "c") +@end example + +This, as you can see, is a fairly sophisticated way to say hello. +@xref{Service Convenience,,, shepherd, The GNU Shepherd Manual}, for more +info on actions. +@end deftp + @defvr {Scheme Variable} shepherd-root-service-type The service type for the Shepherd ``root service''---i.e., PID@tie{}1. diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index 6ca53faa3d..4cd2249841 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm @@ -49,6 +49,12 @@ shepherd-service-auto-start? shepherd-service-modules + shepherd-action + shepherd-action? + shepherd-action-name + shepherd-action-documentation + shepherd-action-procedure + %default-modules shepherd-service-file @@ -146,11 +152,20 @@ DEFAULT is given, use it as the service's default value." (start shepherd-service-start) ;g-expression (procedure) (stop shepherd-service-stop ;g-expression (procedure) (default #~(const #f))) + (actions shepherd-service-actions ;list of + (default '())) (auto-start? shepherd-service-auto-start? ;Boolean (default #t)) (modules shepherd-service-modules ;list of module names (default %default-modules))) +(define-record-type* + shepherd-action make-shepherd-action + shepherd-action? + (name shepherd-action-name) ;symbol + (procedure shepherd-action-procedure) ;gexp + (documentation shepherd-action-documentation)) ;string + (define (shepherd-service-canonical-name service) "Return the 'canonical name' of SERVICE." (first (shepherd-service-provision service))) @@ -223,7 +238,13 @@ stored." #:requires '#$(shepherd-service-requirement service) #:respawn? '#$(shepherd-service-respawn? service) #:start #$(shepherd-service-start service) - #:stop #$(shepherd-service-stop service)))))) + #:stop #$(shepherd-service-stop service) + #:actions + (make-actions + #$@(map (match-lambda + (($ name proc doc) + #~(#$name #$doc #$proc))) + (shepherd-service-actions service)))))))) (define (shepherd-configuration-file services) "Return the shepherd configuration file for SERVICES." -- cgit 1.4.1 From 147c5aa5d4e3bd21ee4c4cae70dff8da0bcf94b7 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 11 Jul 2018 23:40:57 +0200 Subject: services: mcron: Add 'schedule' action. Inspired by . * gnu/services/mcron.scm (shepherd-schedule-action): New procedure. (mcron-shepherd-services): Add 'actions' field. * gnu/tests/base.scm (run-mcron-test)["schedule action"]: New test. * doc/guix.texi (Scheduled Job Execution): Mention 'herd schedule'. --- doc/guix.texi | 15 ++++++++++ gnu/services/herd.scm | 3 ++ gnu/services/mcron.scm | 76 +++++++++++++++++++++++++++++++++++++++----------- gnu/tests/base.scm | 7 +++++ 4 files changed, 84 insertions(+), 17 deletions(-) (limited to 'gnu/services') diff --git a/doc/guix.texi b/doc/guix.texi index 34012a357b..eaec4c422b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10850,6 +10850,21 @@ gexps to introduce job definitions that are passed to mcron for more information on mcron job specifications. Below is the reference of the mcron service. +On a running system, you can use the @code{schedule} action of the service to +visualize the mcron jobs that will be executed next: + +@example +# herd schedule mcron +@end example + +@noindent +The example above lists the next five tasks that will be executed, but you can +also specify the number of tasks to display: + +@example +# herd schedule mcron 10 +@end example + @deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron}] Return an mcron service running @var{mcron} that schedules @var{jobs}, a list of gexps denoting mcron job specifications. diff --git a/gnu/services/herd.scm b/gnu/services/herd.scm index d882c232cf..8c96b70731 100644 --- a/gnu/services/herd.scm +++ b/gnu/services/herd.scm @@ -45,6 +45,7 @@ live-service-requirement live-service-running + with-shepherd-action current-services unload-services unload-service @@ -168,6 +169,8 @@ return #f." (define-syntax-rule (with-shepherd-action service (action args ...) result body ...) + "Invoke ACTION on SERVICE with the given ARGS, and evaluate BODY with RESULT +bound to the action's result." (invoke-action service action (list args ...) (lambda (result) body ...))) diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm index 5bee02a587..5757bf8cf6 100644 --- a/gnu/services/mcron.scm +++ b/gnu/services/mcron.scm @@ -60,29 +60,71 @@ (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 ()) ;nothing to do! '()) (($ mcron jobs) - (list (shepherd-service - (provision '(mcron)) - (requirement '(user-processes)) - (modules `((srfi srfi-1) - (srfi srfi-26) - ,@%default-modules)) - (start #~(make-forkexec-constructor - (list (string-append #$mcron "/bin/mcron") - #$@(map job-file 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)) - ;; 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) diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm index 0efb4a6e55..f27064af85 100644 --- a/gnu/tests/base.scm +++ b/gnu/tests/base.scm @@ -632,6 +632,13 @@ non-ASCII names from /tmp.") (wait-for-file "/root/witness-touch" marionette #:read '(@ (ice-9 rdelim) read-string))) + ;; Make sure the 'schedule' action is accepted. + (test-equal "schedule action" + '(#t) ;one value, #t + (marionette-eval '(with-shepherd-action 'mcron ('schedule) result + result) + marionette)) + (test-end) (exit (= (test-runner-fail-count (test-runner-current)) 0))))) -- cgit 1.4.1 From daf823ad27d2db8a392c269cfe7940ad8cb1f4c1 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sat, 14 Jul 2018 13:18:24 +0200 Subject: gnu: services: Export virtlog-configuration. * gnu/services/virtualization.scm (virtlog-configuration): Export. --- gnu/services/virtualization.scm | 1 + 1 file changed, 1 insertion(+) (limited to 'gnu/services') diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm index bf71e7f26a..705ed84d06 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm @@ -37,6 +37,7 @@ #:export (libvirt-configuration libvirt-service-type + virtlog-configuration virtlog-service-type %qemu-platforms -- cgit 1.4.1 From cd62e5d36835a7ec7b003500f1d1ad58b09738e3 Mon Sep 17 00:00:00 2001 From: Clément Lassieur Date: Sun, 15 Jul 2018 13:18:00 +0200 Subject: services: cuirass: Remove the LOAD-PATH option. * gnu/services/cuirass.scm (, cuirass-shepherd-service): Remove the LOAD-PATH option. --- gnu/services/cuirass.scm | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'gnu/services') diff --git a/gnu/services/cuirass.scm b/gnu/services/cuirass.scm index 4664a36dcf..9c62080629 100644 --- a/gnu/services/cuirass.scm +++ b/gnu/services/cuirass.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2017 Jan Nieuwenhuizen ;;; Copyright © 2018 Ricardo Wurmus +;;; Copyright © 2018 Clément Lassieur ;;; ;;; This file is part of GNU Guix. ;;; @@ -72,9 +73,7 @@ (one-shot? cuirass-configuration-one-shot? ;boolean (default #f)) (fallback? cuirass-configuration-fallback? ;boolean - (default #f)) - (load-path cuirass-configuration-load-path - (default '()))) + (default #f))) (define (cuirass-shepherd-service config) "Return a for the Cuirass service with CONFIG." @@ -92,8 +91,7 @@ (specs (cuirass-configuration-specifications config)) (use-substitutes? (cuirass-configuration-use-substitutes? config)) (one-shot? (cuirass-configuration-one-shot? config)) - (fallback? (cuirass-configuration-fallback? config)) - (load-path (cuirass-configuration-load-path config))) + (fallback? (cuirass-configuration-fallback? config))) (list (shepherd-service (documentation "Run Cuirass.") (provision '(cuirass)) @@ -109,9 +107,7 @@ "--interval" #$(number->string interval) #$@(if use-substitutes? '("--use-substitutes") '()) #$@(if one-shot? '("--one-shot") '()) - #$@(if fallback? '("--fallback") '()) - #$@(if (null? load-path) '() - `("--load-path" ,(string-join load-path ":")))) + #$@(if fallback? '("--fallback") '())) #:environment-variables (list "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt" -- cgit 1.4.1 From 363c946b36a77aa6f0e60b8c93a171d2e649164f Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Wed, 18 Jul 2018 21:15:18 +0200 Subject: gnu: services: Fix openssh service start error. * gnu/services/ssh.scm (openssh-shepherd-service): Require loopback. --- gnu/services/ssh.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnu/services') diff --git a/gnu/services/ssh.scm b/gnu/services/ssh.scm index f1d2be3f6b..f158fdf01f 100644 --- a/gnu/services/ssh.scm +++ b/gnu/services/ssh.scm @@ -455,7 +455,7 @@ of user-name/file-like tuples." (list (shepherd-service (documentation "OpenSSH server.") - (requirement '(syslogd)) + (requirement '(syslogd loopback)) (provision '(ssh-daemon)) (start #~(make-forkexec-constructor #$openssh-command #:pid-file #$pid-file)) -- cgit 1.4.1