[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/10: services: zabbix-server: Add shepherd actions for runtime control
From: |
guix-commits |
Subject: |
05/10: services: zabbix-server: Add shepherd actions for runtime control commands. |
Date: |
Sat, 29 Jan 2022 06:53:59 -0500 (EST) |
mbakke pushed a commit to branch master
in repository guix.
commit 5122805c4849034c567ca90be5de8117b2581b3e
Author: Marius Bakke <marius@gnu.org>
AuthorDate: Fri Jan 28 14:34:59 2022 +0100
services: zabbix-server: Add shepherd actions for runtime control commands.
* gnu/services/monitoring.scm (zabbix-server-runtime-control-procedure,
zabbix-server-actions): New variables.
(zabbix-server-shepherd-service)[actions]: New field. Let-bind variables
common between actions and the start procedure.
---
gnu/services/monitoring.scm | 76 +++++++++++++++++++++++++++++++++++----------
1 file changed, 60 insertions(+), 16 deletions(-)
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index 957672882a..a331bf1117 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.org>
;;; Copyright © 2018, 2019 Gábor Boskovits <boskovits@gmail.com>
;;; Copyright © 2018, 2019, 2020 Oleg Pykhalov <go.wigust@gmail.com>
+;;; Copyright © 2022 Marius Bakke <marius@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -334,7 +335,6 @@ configuration file."))
#~(begin
(use-modules (guix build utils)
(ice-9 rdelim))
-
(let ((user (getpw #$(zabbix-server-configuration-user config))))
(for-each (lambda (file)
(let ((directory (dirname file)))
@@ -345,25 +345,69 @@ configuration file."))
#$(zabbix-server-configuration-pid-file config)
"/etc/zabbix/maintenance.inc.php"))))))
+(define (zabbix-server-runtime-control-procedure zabbix-server config command)
+ ;; XXX: This is duplicated from mcron; factorize.
+ #~(lambda (_ . args)
+ ;; Run 'zabbix_server' 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 (apply open-pipe* OPEN_READ #$zabbix-server
+ "--config" #$config
+ "-R" #$command args)))
+ (let loop ()
+ (match (read-line pipe 'concat)
+ ((? eof-object?)
+ (catch 'system-error
+ (lambda ()
+ (zero? (close-pipe pipe)))
+ (lambda args
+ ;; There's a race with the SIGCHLD handler, which could
+ ;; call 'waitpid' before 'close-pipe' above does. If we
+ ;; get ECHILD, that means we lost the race; in that case, we
+ ;; cannot tell what the exit code was (FIXME).
+ (or (= ECHILD (system-error-errno args))
+ (apply throw args)))))
+ (line
+ (display line)
+ (loop)))))))
+
+;; Provide shepherd actions for common "zabbix_server -R" commands
+;; mainly for a convenient way to use the correct configuration file.
+(define (zabbix-server-actions zabbix-server config)
+ (list (shepherd-action
+ (name 'reload-config-cache)
+ (documentation "Reload the configuration cache.")
+ (procedure (zabbix-server-runtime-control-procedure
+ zabbix-server config "config_cache_reload")))
+ (shepherd-action
+ (name 'reload-snmp-cache)
+ (documentation "Reload SNMP cache.")
+ (procedure (zabbix-server-runtime-control-procedure
+ zabbix-server config "snmp_cache_reload")))))
+
(define (zabbix-server-shepherd-service config)
"Return a <shepherd-service> for Zabbix server with CONFIG."
- (list (shepherd-service
- (provision '(zabbix-server))
- (documentation "Run Zabbix server daemon.")
- (start #~(make-forkexec-constructor
- (list #$(file-append
(zabbix-server-configuration-zabbix-server config)
- "/sbin/zabbix_server")
- "--config" #$(zabbix-server-config-file config)
- "--foreground")
- #:user #$(zabbix-server-configuration-user config)
- #:group #$(zabbix-server-configuration-group config)
- #:pid-file #$(zabbix-server-configuration-pid-file config)
- #:environment-variables
- (list "SSL_CERT_DIR=/run/current-system/profile\
+ (let ((zabbix-server
+ (file-append (zabbix-server-configuration-zabbix-server config)
+ "/sbin/zabbix_server"))
+ (config-file (zabbix-server-config-file config)))
+ (list (shepherd-service
+ (provision '(zabbix-server))
+ (documentation "Run the Zabbix server daemon.")
+ (actions (zabbix-server-actions zabbix-server config-file))
+ (start #~(make-forkexec-constructor
+ (list #$zabbix-server
+ "--config" #$config-file
+ "--foreground")
+ #:user #$(zabbix-server-configuration-user config)
+ #:group #$(zabbix-server-configuration-group config)
+ #:pid-file #$(zabbix-server-configuration-pid-file config)
+ #:environment-variables
+ (list "SSL_CERT_DIR=/run/current-system/profile\
/etc/ssl/certs"
- "SSL_CERT_FILE=/run/current-system/profile\
+ "SSL_CERT_FILE=/run/current-system/profile\
/etc/ssl/certs/ca-certificates.crt")))
- (stop #~(make-kill-destructor)))))
+ (stop #~(make-kill-destructor))))))
(define zabbix-server-service-type
(service-type
- branch master updated (69218e84f1 -> 45681b89a8), guix-commits, 2022/01/29
- 03/10: gnu: fping: Enable IPv6 support., guix-commits, 2022/01/29
- 02/10: services: zabbix-frontend: Fix configuration file for hard coded passwords., guix-commits, 2022/01/29
- 05/10: services: zabbix-server: Add shepherd actions for runtime control commands.,
guix-commits <=
- 01/10: gnu: python-pydantic: Update to 1.9.0., guix-commits, 2022/01/29
- 04/10: gnu: zabbix-server: Use a sensible default for the "fping" executable., guix-commits, 2022/01/29
- 08/10: gnu: Add TimescaleDB., guix-commits, 2022/01/29
- 10/10: gnu: zabbix: Update to 5.4.9., guix-commits, 2022/01/29
- 07/10: services: zabbix-frontend: Adjust indentation., guix-commits, 2022/01/29
- 09/10: services: zabbix-agent: Set the PATH variable., guix-commits, 2022/01/29
- 06/10: services: zabbix-frontend: Enable IEEE754-compatible history values., guix-commits, 2022/01/29