services: syslog: Move configuration to /etc/syslog.conf.

Having the configuration live at a static location makes it possible to
hot-reload it.

* gnu/services/base.scm (syslog.conf): New variable.
(syslog-etc, syslog-shepherd-service): New procedures.
(syslog-service-type): Rewrite using the above new variable and procedures,
extending etc-service-type with its configuration file.
This commit is contained in:
Maxim Cournoyer 2023-04-12 19:55:44 -04:00
parent 184658e282
commit 1ae279d7c8
No known key found for this signature in database
GPG key ID: 1260E46482E63562

View file

@ -15,7 +15,7 @@
;;; Copyright © 2020, 2021 Brice Waegeneire <brice@waegenei.re> ;;; Copyright © 2020, 2021 Brice Waegeneire <brice@waegenei.re>
;;; Copyright © 2021 qblade <qblade@protonmail.com> ;;; Copyright © 2021 qblade <qblade@protonmail.com>
;;; Copyright © 2021 Hui Lu <luhuins@163.com> ;;; Copyright © 2021 Hui Lu <luhuins@163.com>
;;; Copyright © 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; Copyright © 2021, 2022, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2021 muradm <mail@muradm.net> ;;; Copyright © 2021 muradm <mail@muradm.net>
;;; Copyright © 2022 Guillaume Le Vaillant <glv@posteo.net> ;;; Copyright © 2022 Guillaume Le Vaillant <glv@posteo.net>
;;; Copyright © 2022 Justin Veilleux <terramorpha@cock.li> ;;; Copyright © 2022 Justin Veilleux <terramorpha@cock.li>
@ -1532,30 +1532,43 @@ (define-record-type* <syslog-configuration>
(config-file syslog-configuration-config-file (config-file syslog-configuration-config-file
(default %default-syslog.conf))) (default %default-syslog.conf)))
(define syslog-service-type ;;; Note: a static file name is used for syslog.conf so that the reload action
(shepherd-service-type ;;; work as intended.
'syslog (define syslog.conf "/etc/syslog.conf")
(lambda (config)
(define config-file
(syslog-configuration-config-file config))
(shepherd-service (define (syslog-etc configuration)
(documentation "Run the syslog daemon (syslogd).") (match-record configuration <syslog-configuration>
(provision '(syslogd)) (config-file)
(requirement '(user-processes)) (list `(,(basename syslog.conf) ,config-file))))
(actions (list (shepherd-configuration-action config-file)))
(start #~(let ((spawn (make-forkexec-constructor (define (syslog-shepherd-service config)
(list #$(syslog-configuration-syslogd config) (define config-file
"--rcfile" #$config-file) (syslog-configuration-config-file config))
#:pid-file "/var/run/syslog.pid")))
(lambda () (shepherd-service
;; Set the umask such that file permissions are #o640. (documentation "Run the syslog daemon (syslogd).")
(let ((mask (umask #o137)) (provision '(syslogd))
(pid (spawn))) (requirement '(user-processes))
(umask mask) (actions (list (shepherd-configuration-action syslog.conf)))
pid)))) (start #~(let ((spawn (make-forkexec-constructor
(stop #~(make-kill-destructor)))) (list #$(syslog-configuration-syslogd config)
(syslog-configuration) #$(string-append "--rcfile=" syslog.conf))
#:pid-file "/var/run/syslog.pid")))
(lambda ()
;; Set the umask such that file permissions are #o640.
(let ((mask (umask #o137))
(pid (spawn)))
(umask mask)
pid))))
(stop #~(make-kill-destructor))))
(define syslog-service-type
(service-type
(name 'syslog)
(default-value (syslog-configuration))
(extensions (list (service-extension shepherd-root-service-type
(compose list syslog-shepherd-service))
(service-extension etc-service-type syslog-etc)))
(description "Run the syslog daemon, @command{syslogd}, which is (description "Run the syslog daemon, @command{syslogd}, which is
responsible for logging system messages."))) responsible for logging system messages.")))