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.
This commit is contained in:
parent
0d347fe83e
commit
5122805c48
|
@ -2,6 +2,7 @@
|
||||||
;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.org>
|
;;; Copyright © 2018 Sou Bunnbu <iyzsong@member.fsf.org>
|
||||||
;;; Copyright © 2018, 2019 Gábor Boskovits <boskovits@gmail.com>
|
;;; Copyright © 2018, 2019 Gábor Boskovits <boskovits@gmail.com>
|
||||||
;;; Copyright © 2018, 2019, 2020 Oleg Pykhalov <go.wigust@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.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -334,7 +335,6 @@ (define (zabbix-server-activation config)
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (guix build utils)
|
(use-modules (guix build utils)
|
||||||
(ice-9 rdelim))
|
(ice-9 rdelim))
|
||||||
|
|
||||||
(let ((user (getpw #$(zabbix-server-configuration-user config))))
|
(let ((user (getpw #$(zabbix-server-configuration-user config))))
|
||||||
(for-each (lambda (file)
|
(for-each (lambda (file)
|
||||||
(let ((directory (dirname file)))
|
(let ((directory (dirname file)))
|
||||||
|
@ -345,25 +345,69 @@ (define (zabbix-server-activation config)
|
||||||
#$(zabbix-server-configuration-pid-file config)
|
#$(zabbix-server-configuration-pid-file config)
|
||||||
"/etc/zabbix/maintenance.inc.php"))))))
|
"/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)
|
(define (zabbix-server-shepherd-service config)
|
||||||
"Return a <shepherd-service> for Zabbix server with CONFIG."
|
"Return a <shepherd-service> for Zabbix server with CONFIG."
|
||||||
(list (shepherd-service
|
(let ((zabbix-server
|
||||||
(provision '(zabbix-server))
|
(file-append (zabbix-server-configuration-zabbix-server config)
|
||||||
(documentation "Run Zabbix server daemon.")
|
"/sbin/zabbix_server"))
|
||||||
(start #~(make-forkexec-constructor
|
(config-file (zabbix-server-config-file config)))
|
||||||
(list #$(file-append (zabbix-server-configuration-zabbix-server config)
|
(list (shepherd-service
|
||||||
"/sbin/zabbix_server")
|
(provision '(zabbix-server))
|
||||||
"--config" #$(zabbix-server-config-file config)
|
(documentation "Run the Zabbix server daemon.")
|
||||||
"--foreground")
|
(actions (zabbix-server-actions zabbix-server config-file))
|
||||||
#:user #$(zabbix-server-configuration-user config)
|
(start #~(make-forkexec-constructor
|
||||||
#:group #$(zabbix-server-configuration-group config)
|
(list #$zabbix-server
|
||||||
#:pid-file #$(zabbix-server-configuration-pid-file config)
|
"--config" #$config-file
|
||||||
#:environment-variables
|
"--foreground")
|
||||||
(list "SSL_CERT_DIR=/run/current-system/profile\
|
#: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"
|
/etc/ssl/certs"
|
||||||
"SSL_CERT_FILE=/run/current-system/profile\
|
"SSL_CERT_FILE=/run/current-system/profile\
|
||||||
/etc/ssl/certs/ca-certificates.crt")))
|
/etc/ssl/certs/ca-certificates.crt")))
|
||||||
(stop #~(make-kill-destructor)))))
|
(stop #~(make-kill-destructor))))))
|
||||||
|
|
||||||
(define zabbix-server-service-type
|
(define zabbix-server-service-type
|
||||||
(service-type
|
(service-type
|
||||||
|
|
Loading…
Reference in a new issue