mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-04-06 21:20:33 +02:00
services: Add and use shepherd-signal-action.
* gnu/services/shepherd.scm (shepherd-signal-action): New procedure. * gnu/services/audio.scm (mpd-shepherd-service): Use it for actions. * gnu/services/base.scm (syslog-shepherd-service): * gnu/services/base.scm (dnsmasq-shepherd-service): * gnu/services/file-sharing.scm (transmission-daemon-shepherd-service): * gnu/services/monitoring.scm (vnstat-shepherd-service): * gnu/services/mail.scm (rspamd-shepherd-service): * doc/guix.texi (shepherd-signal-action): Document it. Change-Id: Ief5e00c7d430ec4aa28c3ef11d0ef9897793b45f Signed-off-by: Ludovic Courtès <ludo@gnu.org> Merges: #6097
This commit is contained in:
committed by
Ludovic Courtès
parent
1ec777def8
commit
6eb6971f4d
@@ -50488,6 +50488,29 @@ cat $(herd configuration tor)
|
|||||||
This can come in as a handy debugging tool!
|
This can come in as a handy debugging tool!
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn {Procedure} shepherd-signal-action name signal @
|
||||||
|
[#:documentation `Send signal @var{signal} to the running service`] @
|
||||||
|
[#:message `Service has been asked to perform @var{name}`]
|
||||||
|
Return a shepherd action with @var{name} to send @var{signal} to the
|
||||||
|
running process. The optional @var{documentation} and @var{message} can be used
|
||||||
|
to customize the documentation and output message.
|
||||||
|
|
||||||
|
Many daemons perform special actions after receiving a specific signal.
|
||||||
|
|
||||||
|
For example the @command{syslogd} logger will reread its configuration file
|
||||||
|
after receiving @code{SIGHUP}.
|
||||||
|
|
||||||
|
After adding
|
||||||
|
@lisp
|
||||||
|
(shepherd-signal-action 'reload SIGHUP))
|
||||||
|
@end lisp
|
||||||
|
|
||||||
|
the @code{reload} action will be available and can be used with
|
||||||
|
@example
|
||||||
|
herd reload syslogd
|
||||||
|
@end example
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@defvar shepherd-root-service-type
|
@defvar shepherd-root-service-type
|
||||||
The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
|
The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
|
||||||
|
|
||||||
|
|||||||
@@ -636,18 +636,10 @@ appended to the configuration.")
|
|||||||
(stop #~(make-kill-destructor))
|
(stop #~(make-kill-destructor))
|
||||||
(actions
|
(actions
|
||||||
(list (shepherd-configuration-action config-file)
|
(list (shepherd-configuration-action config-file)
|
||||||
(shepherd-action
|
(shepherd-signal-action
|
||||||
(name 'reopen)
|
'reopen SIGHUP
|
||||||
(documentation "Re-open log files and flush caches.")
|
#:documentation "Re-open log files and flush caches."
|
||||||
(procedure
|
#:message "Issued SIGHUP to Service MPD.")))))))
|
||||||
#~(lambda (pid)
|
|
||||||
(if pid
|
|
||||||
(begin
|
|
||||||
(kill pid SIGHUP)
|
|
||||||
(format #t
|
|
||||||
"Issued SIGHUP to Service MPD (PID ~a)."
|
|
||||||
pid))
|
|
||||||
(format #t "Service MPD is not running.")))))))))))
|
|
||||||
|
|
||||||
(define (mpd-accounts config)
|
(define (mpd-accounts config)
|
||||||
(match-record config <mpd-configuration> (user group)
|
(match-record config <mpd-configuration> (user group)
|
||||||
|
|||||||
@@ -1708,17 +1708,11 @@ mail.* -/var/log/maillog
|
|||||||
(requirement '(user-processes))
|
(requirement '(user-processes))
|
||||||
(actions
|
(actions
|
||||||
(list (shepherd-configuration-action syslog.conf)
|
(list (shepherd-configuration-action syslog.conf)
|
||||||
(shepherd-action
|
(shepherd-signal-action
|
||||||
(name 'reload)
|
'reload SIGHUP
|
||||||
(documentation "Reload the configuration file from disk.")
|
#:documentation "Reload the configuration file from disk."
|
||||||
(procedure
|
#:message "Service syslog has been asked to \
|
||||||
#~(lambda (pid)
|
|
||||||
(if pid
|
|
||||||
(begin
|
|
||||||
(kill pid SIGHUP)
|
|
||||||
(display #$(G_ "Service syslog has been asked to \
|
|
||||||
reload its settings file.")))
|
reload its settings file.")))
|
||||||
(display #$(G_ "Service syslog is not running."))))))))
|
|
||||||
;; Note: a static file name is used for syslog.conf so that the reload
|
;; Note: a static file name is used for syslog.conf so that the reload
|
||||||
;; action work as intended.
|
;; action work as intended.
|
||||||
(start #~(make-forkexec-constructor
|
(start #~(make-forkexec-constructor
|
||||||
|
|||||||
@@ -969,24 +969,16 @@ cache.size = 100 * MB
|
|||||||
(mkdir-p "/var/lib/misc")))
|
(mkdir-p "/var/lib/misc")))
|
||||||
|
|
||||||
(define (dnsmasq-service-reload-action config)
|
(define (dnsmasq-service-reload-action config)
|
||||||
(match-record config <dnsmasq-configuration> ()
|
(shepherd-signal-action
|
||||||
(shepherd-action
|
'reload SIGHUP
|
||||||
(name 'reload)
|
#:documentation "Send a @code{SIGHUP} signal to @command{dnsmasq} to clear
|
||||||
(documentation "Send a @code{SIGHUP} signal to @command{dnsmasq} to clear
|
cache and reload hosts files."))
|
||||||
cache and reload hosts files.")
|
|
||||||
(procedure #~(lambda (running)
|
|
||||||
(let ((pid (process-id running)))
|
|
||||||
(kill pid SIGHUP)))))))
|
|
||||||
|
|
||||||
(define (dnsmasq-service-stats-action config)
|
(define (dnsmasq-service-stats-action config)
|
||||||
(match-record config <dnsmasq-configuration> ()
|
(shepherd-signal-action
|
||||||
(shepherd-action
|
'stats SIGUSR1
|
||||||
(name 'stats)
|
#:documentation "Send a @code{SIGUSR1} to write statistics to the system
|
||||||
(documentation "Send a @code{SIGUSR1} to write statistics to the system
|
log."))
|
||||||
log.")
|
|
||||||
(procedure #~(lambda (running)
|
|
||||||
(let ((pid (process-id running)))
|
|
||||||
(kill pid SIGUSR1)))))))
|
|
||||||
|
|
||||||
(define dnsmasq-service-type
|
(define dnsmasq-service-type
|
||||||
(service-type
|
(service-type
|
||||||
|
|||||||
@@ -656,17 +656,11 @@ satisfy requests from peers."))
|
|||||||
|
|
||||||
(actions
|
(actions
|
||||||
(list
|
(list
|
||||||
(shepherd-action
|
(shepherd-signal-action
|
||||||
(name 'reload)
|
'reload SIGHUP
|
||||||
(documentation "Reload the settings file from disk.")
|
#:documentation "Reload the settings file from disk."
|
||||||
(procedure #~(lambda (pid)
|
#:message "Service transmission-daemon has \
|
||||||
(if pid
|
been asked to reload its settings file.")))))))
|
||||||
(begin
|
|
||||||
(kill pid SIGHUP)
|
|
||||||
(display #$(G_ "Service transmission-daemon has \
|
|
||||||
been asked to reload its settings file.")))
|
|
||||||
(display #$(G_ "Service transmission-daemon is not \
|
|
||||||
running."))))))))))))
|
|
||||||
|
|
||||||
(define %transmission-daemon-accounts
|
(define %transmission-daemon-accounts
|
||||||
(list (user-group
|
(list (user-group
|
||||||
|
|||||||
@@ -2483,26 +2483,14 @@ worker \"fuzzy\" {
|
|||||||
(actions
|
(actions
|
||||||
(list
|
(list
|
||||||
(shepherd-configuration-action config-file)
|
(shepherd-configuration-action config-file)
|
||||||
(shepherd-action
|
(shepherd-signal-action
|
||||||
(name 'reload)
|
'reload SIGHUP
|
||||||
(documentation "Reload rspamd.")
|
#:documentation "Reload rspamd."
|
||||||
(procedure
|
#:message "Service rspamd has been reloaded")
|
||||||
#~(lambda (pid)
|
(shepherd-signal-action
|
||||||
(if pid
|
'reopen SIGUSR1
|
||||||
(begin
|
#:documentation "Reopen log files."
|
||||||
(kill pid SIGHUP)
|
#:message "Reopening the logs for rspamd.")))))))
|
||||||
(display "Service rspamd has been reloaded"))
|
|
||||||
(format #t "Service rspamd is not running.")))))
|
|
||||||
(shepherd-action
|
|
||||||
(name 'reopen)
|
|
||||||
(documentation "Reopen log files.")
|
|
||||||
(procedure
|
|
||||||
#~(lambda (pid)
|
|
||||||
(if pid
|
|
||||||
(begin
|
|
||||||
(kill pid SIGUSR1)
|
|
||||||
(display "Reopening the logs for rspamd"))
|
|
||||||
(format #t "Service rspamd is not running.")))))))))))
|
|
||||||
|
|
||||||
(define rspamd-service-type
|
(define rspamd-service-type
|
||||||
(service-type
|
(service-type
|
||||||
|
|||||||
@@ -640,18 +640,10 @@ resolution.")
|
|||||||
(stop #~(make-kill-destructor))
|
(stop #~(make-kill-destructor))
|
||||||
(actions
|
(actions
|
||||||
(list (shepherd-configuration-action config-file)
|
(list (shepherd-configuration-action config-file)
|
||||||
(shepherd-action
|
(shepherd-signal-action
|
||||||
(name 'reload)
|
'reload SIGHUP
|
||||||
(documentation "Reload vnstatd.")
|
#:documentation "Reload vnstatd."
|
||||||
(procedure
|
#:message "Issued SIGHUP to vnstatd.")))))))
|
||||||
#~(lambda (pid)
|
|
||||||
(if pid
|
|
||||||
(begin
|
|
||||||
(kill pid SIGHUP)
|
|
||||||
(format #t
|
|
||||||
"Issued SIGHUP to vnstatd (PID ~a)."
|
|
||||||
pid))
|
|
||||||
(format #t "vnstatd is not running.")))))))))))
|
|
||||||
|
|
||||||
(define (vnstat-account-service config)
|
(define (vnstat-account-service config)
|
||||||
(match-record config <vnstat-configuration> (daemon-group daemon-user)
|
(match-record config <vnstat-configuration> (daemon-group daemon-user)
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
shepherd-action-documentation
|
shepherd-action-documentation
|
||||||
shepherd-action-procedure
|
shepherd-action-procedure
|
||||||
|
|
||||||
|
shepherd-signal-action
|
||||||
shepherd-configuration-action
|
shepherd-configuration-action
|
||||||
shepherd-timer
|
shepherd-timer
|
||||||
shepherd-trigger-action
|
shepherd-trigger-action
|
||||||
@@ -421,6 +422,26 @@ and return the resulting '.go' file. SHEPHERD is used as shepherd package."
|
|||||||
#:options '(#:local-build? #t
|
#:options '(#:local-build? #t
|
||||||
#:substitutable? #f)))))
|
#:substitutable? #f)))))
|
||||||
|
|
||||||
|
(define* (shepherd-signal-action
|
||||||
|
name signal
|
||||||
|
#:key
|
||||||
|
(documentation (format #f "Send signal ~a to the running service."
|
||||||
|
signal))
|
||||||
|
(message (format #f "Service has been asked to perform '~a'."
|
||||||
|
name)))
|
||||||
|
"Return a shepherd action with NAME to send SIGNAL to the running process.
|
||||||
|
The documentation string of the action will be set to DOC.
|
||||||
|
The action will print MESSAGE after sending the signal."
|
||||||
|
(shepherd-action
|
||||||
|
(name name)
|
||||||
|
(documentation documentation)
|
||||||
|
(procedure #~(lambda (running . args)
|
||||||
|
(if running
|
||||||
|
(let ((pid (process-id running)))
|
||||||
|
(kill pid #$signal)
|
||||||
|
(display #$message))
|
||||||
|
(display "Service is not running."))))))
|
||||||
|
|
||||||
(define (shepherd-configuration-action file)
|
(define (shepherd-configuration-action file)
|
||||||
"Return a 'configuration' action to display FILE, which should be the name
|
"Return a 'configuration' action to display FILE, which should be the name
|
||||||
of the service's configuration file."
|
of the service's configuration file."
|
||||||
|
|||||||
Reference in New Issue
Block a user