diff options
| author | Yelninei <yelninei@tutamail.com> | 2026-02-03 08:30:53 +0000 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2026-03-11 18:27:46 +0100 |
| commit | 6eb6971f4d721fc8d648323f0dbd52d0697b2a7b (patch) | |
| tree | 3f7a3a67aaaacc584f24e87622dee3e0d403f9b1 /gnu/services | |
| parent | 1ec777def84fcce9cfe77acb2ce3112b04b37085 (diff) | |
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
Diffstat (limited to 'gnu/services')
| -rw-r--r-- | gnu/services/audio.scm | 16 | ||||
| -rw-r--r-- | gnu/services/base.scm | 14 | ||||
| -rw-r--r-- | gnu/services/dns.scm | 24 | ||||
| -rw-r--r-- | gnu/services/file-sharing.scm | 16 | ||||
| -rw-r--r-- | gnu/services/mail.scm | 28 | ||||
| -rw-r--r-- | gnu/services/monitoring.scm | 16 | ||||
| -rw-r--r-- | gnu/services/shepherd.scm | 21 |
7 files changed, 54 insertions, 81 deletions
diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm index 5091d7fc137..517ed8fc5bf 100644 --- a/gnu/services/audio.scm +++ b/gnu/services/audio.scm | |||
| @@ -636,18 +636,10 @@ appended to the configuration.") | |||
| 636 | (stop #~(make-kill-destructor)) | 636 | (stop #~(make-kill-destructor)) |
| 637 | (actions | 637 | (actions |
| 638 | (list (shepherd-configuration-action config-file) | 638 | (list (shepherd-configuration-action config-file) |
| 639 | (shepherd-action | 639 | (shepherd-signal-action |
| 640 | (name 'reopen) | 640 | 'reopen SIGHUP |
| 641 | (documentation "Re-open log files and flush caches.") | 641 | #:documentation "Re-open log files and flush caches." |
| 642 | (procedure | 642 | #:message "Issued SIGHUP to Service MPD."))))))) |
| 643 | #~(lambda (pid) | ||
| 644 | (if pid | ||
| 645 | (begin | ||
| 646 | (kill pid SIGHUP) | ||
| 647 | (format #t | ||
| 648 | "Issued SIGHUP to Service MPD (PID ~a)." | ||
| 649 | pid)) | ||
| 650 | (format #t "Service MPD is not running."))))))))))) | ||
| 651 | 643 | ||
| 652 | (define (mpd-accounts config) | 644 | (define (mpd-accounts config) |
| 653 | (match-record config <mpd-configuration> (user group) | 645 | (match-record config <mpd-configuration> (user group) |
diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 0ccc6089771..31ae0cb9374 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm | |||
| @@ -1708,17 +1708,11 @@ mail.* -/var/log/maillog | |||
| 1708 | (requirement '(user-processes)) | 1708 | (requirement '(user-processes)) |
| 1709 | (actions | 1709 | (actions |
| 1710 | (list (shepherd-configuration-action syslog.conf) | 1710 | (list (shepherd-configuration-action syslog.conf) |
| 1711 | (shepherd-action | 1711 | (shepherd-signal-action |
| 1712 | (name 'reload) | 1712 | 'reload SIGHUP |
| 1713 | (documentation "Reload the configuration file from disk.") | 1713 | #:documentation "Reload the configuration file from disk." |
| 1714 | (procedure | 1714 | #:message "Service syslog has been asked to \ |
| 1715 | #~(lambda (pid) | ||
| 1716 | (if pid | ||
| 1717 | (begin | ||
| 1718 | (kill pid SIGHUP) | ||
| 1719 | (display #$(G_ "Service syslog has been asked to \ | ||
| 1720 | reload its settings file."))) | 1715 | reload its settings file."))) |
| 1721 | (display #$(G_ "Service syslog is not running.")))))))) | ||
| 1722 | ;; Note: a static file name is used for syslog.conf so that the reload | 1716 | ;; Note: a static file name is used for syslog.conf so that the reload |
| 1723 | ;; action work as intended. | 1717 | ;; action work as intended. |
| 1724 | (start #~(make-forkexec-constructor | 1718 | (start #~(make-forkexec-constructor |
diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 42a65a27677..e0cab485884 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm | |||
| @@ -969,24 +969,16 @@ cache.size = 100 * MB | |||
| 969 | (mkdir-p "/var/lib/misc"))) | 969 | (mkdir-p "/var/lib/misc"))) |
| 970 | 970 | ||
| 971 | (define (dnsmasq-service-reload-action config) | 971 | (define (dnsmasq-service-reload-action config) |
| 972 | (match-record config <dnsmasq-configuration> () | 972 | (shepherd-signal-action |
| 973 | (shepherd-action | 973 | 'reload SIGHUP |
| 974 | (name 'reload) | 974 | #:documentation "Send a @code{SIGHUP} signal to @command{dnsmasq} to clear |
| 975 | (documentation "Send a @code{SIGHUP} signal to @command{dnsmasq} to clear | 975 | cache and reload hosts files.")) |
| 976 | cache and reload hosts files.") | ||
| 977 | (procedure #~(lambda (running) | ||
| 978 | (let ((pid (process-id running))) | ||
| 979 | (kill pid SIGHUP))))))) | ||
| 980 | 976 | ||
| 981 | (define (dnsmasq-service-stats-action config) | 977 | (define (dnsmasq-service-stats-action config) |
| 982 | (match-record config <dnsmasq-configuration> () | 978 | (shepherd-signal-action |
| 983 | (shepherd-action | 979 | 'stats SIGUSR1 |
| 984 | (name 'stats) | 980 | #:documentation "Send a @code{SIGUSR1} to write statistics to the system |
| 985 | (documentation "Send a @code{SIGUSR1} to write statistics to the system | 981 | log.")) |
| 986 | log.") | ||
| 987 | (procedure #~(lambda (running) | ||
| 988 | (let ((pid (process-id running))) | ||
| 989 | (kill pid SIGUSR1))))))) | ||
| 990 | 982 | ||
| 991 | (define dnsmasq-service-type | 983 | (define dnsmasq-service-type |
| 992 | (service-type | 984 | (service-type |
diff --git a/gnu/services/file-sharing.scm b/gnu/services/file-sharing.scm index d0e9a8ca901..be4a694cd13 100644 --- a/gnu/services/file-sharing.scm +++ b/gnu/services/file-sharing.scm | |||
| @@ -656,17 +656,11 @@ satisfy requests from peers.")) | |||
| 656 | 656 | ||
| 657 | (actions | 657 | (actions |
| 658 | (list | 658 | (list |
| 659 | (shepherd-action | 659 | (shepherd-signal-action |
| 660 | (name 'reload) | 660 | 'reload SIGHUP |
| 661 | (documentation "Reload the settings file from disk.") | 661 | #:documentation "Reload the settings file from disk." |
| 662 | (procedure #~(lambda (pid) | 662 | #:message "Service transmission-daemon has \ |
| 663 | (if pid | 663 | been asked to reload its settings file."))))))) |
| 664 | (begin | ||
| 665 | (kill pid SIGHUP) | ||
| 666 | (display #$(G_ "Service transmission-daemon has \ | ||
| 667 | been asked to reload its settings file."))) | ||
| 668 | (display #$(G_ "Service transmission-daemon is not \ | ||
| 669 | running.")))))))))))) | ||
| 670 | 664 | ||
| 671 | (define %transmission-daemon-accounts | 665 | (define %transmission-daemon-accounts |
| 672 | (list (user-group | 666 | (list (user-group |
diff --git a/gnu/services/mail.scm b/gnu/services/mail.scm index 5d4bc4684d3..70825dd1a9d 100644 --- a/gnu/services/mail.scm +++ b/gnu/services/mail.scm | |||
| @@ -2483,26 +2483,14 @@ worker \"fuzzy\" { | |||
| 2483 | (actions | 2483 | (actions |
| 2484 | (list | 2484 | (list |
| 2485 | (shepherd-configuration-action config-file) | 2485 | (shepherd-configuration-action config-file) |
| 2486 | (shepherd-action | 2486 | (shepherd-signal-action |
| 2487 | (name 'reload) | 2487 | 'reload SIGHUP |
| 2488 | (documentation "Reload rspamd.") | 2488 | #:documentation "Reload rspamd." |
| 2489 | (procedure | 2489 | #:message "Service rspamd has been reloaded") |
| 2490 | #~(lambda (pid) | 2490 | (shepherd-signal-action |
| 2491 | (if pid | 2491 | 'reopen SIGUSR1 |
| 2492 | (begin | 2492 | #:documentation "Reopen log files." |
| 2493 | (kill pid SIGHUP) | 2493 | #:message "Reopening the logs for rspamd."))))))) |
| 2494 | (display "Service rspamd has been reloaded")) | ||
| 2495 | (format #t "Service rspamd is not running."))))) | ||
| 2496 | (shepherd-action | ||
| 2497 | (name 'reopen) | ||
| 2498 | (documentation "Reopen log files.") | ||
| 2499 | (procedure | ||
| 2500 | #~(lambda (pid) | ||
| 2501 | (if pid | ||
| 2502 | (begin | ||
| 2503 | (kill pid SIGUSR1) | ||
| 2504 | (display "Reopening the logs for rspamd")) | ||
| 2505 | (format #t "Service rspamd is not running."))))))))))) | ||
| 2506 | 2494 | ||
| 2507 | (define rspamd-service-type | 2495 | (define rspamd-service-type |
| 2508 | (service-type | 2496 | (service-type |
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm index f504c61afdf..8ba19ddd7ee 100644 --- a/gnu/services/monitoring.scm +++ b/gnu/services/monitoring.scm | |||
| @@ -640,18 +640,10 @@ resolution.") | |||
| 640 | (stop #~(make-kill-destructor)) | 640 | (stop #~(make-kill-destructor)) |
| 641 | (actions | 641 | (actions |
| 642 | (list (shepherd-configuration-action config-file) | 642 | (list (shepherd-configuration-action config-file) |
| 643 | (shepherd-action | 643 | (shepherd-signal-action |
| 644 | (name 'reload) | 644 | 'reload SIGHUP |
| 645 | (documentation "Reload vnstatd.") | 645 | #:documentation "Reload vnstatd." |
| 646 | (procedure | 646 | #:message "Issued SIGHUP to vnstatd."))))))) |
| 647 | #~(lambda (pid) | ||
| 648 | (if pid | ||
| 649 | (begin | ||
| 650 | (kill pid SIGHUP) | ||
| 651 | (format #t | ||
| 652 | "Issued SIGHUP to vnstatd (PID ~a)." | ||
| 653 | pid)) | ||
| 654 | (format #t "vnstatd is not running."))))))))))) | ||
| 655 | 647 | ||
| 656 | (define (vnstat-account-service config) | 648 | (define (vnstat-account-service config) |
| 657 | (match-record config <vnstat-configuration> (daemon-group daemon-user) | 649 | (match-record config <vnstat-configuration> (daemon-group daemon-user) |
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index 1c5f6606153..89c8fd3a135 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm | |||
| @@ -71,6 +71,7 @@ | |||
| 71 | shepherd-action-documentation | 71 | shepherd-action-documentation |
| 72 | shepherd-action-procedure | 72 | shepherd-action-procedure |
| 73 | 73 | ||
| 74 | shepherd-signal-action | ||
| 74 | shepherd-configuration-action | 75 | shepherd-configuration-action |
| 75 | shepherd-timer | 76 | shepherd-timer |
| 76 | shepherd-trigger-action | 77 | shepherd-trigger-action |
| @@ -421,6 +422,26 @@ and return the resulting '.go' file. SHEPHERD is used as shepherd package." | |||
| 421 | #:options '(#:local-build? #t | 422 | #:options '(#:local-build? #t |
| 422 | #:substitutable? #f))))) | 423 | #:substitutable? #f))))) |
| 423 | 424 | ||
| 425 | (define* (shepherd-signal-action | ||
| 426 | name signal | ||
| 427 | #:key | ||
| 428 | (documentation (format #f "Send signal ~a to the running service." | ||
| 429 | signal)) | ||
| 430 | (message (format #f "Service has been asked to perform '~a'." | ||
| 431 | name))) | ||
| 432 | "Return a shepherd action with NAME to send SIGNAL to the running process. | ||
| 433 | The documentation string of the action will be set to DOC. | ||
| 434 | The action will print MESSAGE after sending the signal." | ||
| 435 | (shepherd-action | ||
| 436 | (name name) | ||
| 437 | (documentation documentation) | ||
| 438 | (procedure #~(lambda (running . args) | ||
| 439 | (if running | ||
| 440 | (let ((pid (process-id running))) | ||
| 441 | (kill pid #$signal) | ||
| 442 | (display #$message)) | ||
| 443 | (display "Service is not running.")))))) | ||
| 444 | |||
| 424 | (define (shepherd-configuration-action file) | 445 | (define (shepherd-configuration-action file) |
| 425 | "Return a 'configuration' action to display FILE, which should be the name | 446 | "Return a 'configuration' action to display FILE, which should be the name |
| 426 | of the service's configuration file." | 447 | of the service's configuration file." |
