[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/06: log-rotation: Add ‘files’ action.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 01/06: log-rotation: Add ‘files’ action. |
Date: |
Sat, 15 Jun 2024 19:16:12 -0400 (EDT) |
civodul pushed a commit to branch devel
in repository shepherd.
commit 2f30e81ebb4855788ce7c138c0a3a6466d60cc10
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Jun 12 17:21:30 2024 +0200
log-rotation: Add ‘files’ action.
* modules/shepherd/service/log-rotation.scm (log-rotation-service)
[action]: Rename to…
[rotation]: … this.
[files-action]: New variable.
Add it to #:actions.
* tests/services/log-rotation.sh: Test it.
* doc/shepherd.texi (Log Rotation Service): Document it.
---
doc/shepherd.texi | 6 ++++++
modules/shepherd/service/log-rotation.scm | 30 ++++++++++++++++++++++++++----
tests/services/log-rotation.sh | 5 +++++
3 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index 595b69e..2a59899 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -1981,6 +1981,12 @@ You can also trigger it explicitly at any time, like so:
herd trigger log-rotation
@end example
+Last, you can list log files subject to rotation:
+
+@example
+herd files log-rotation
+@end example
+
The default settings should be good for most use cases, but you can
change them by passing the @code{log-rotation-service} procedure a
number of arguments---see the reference documentation below.
diff --git a/modules/shepherd/service/log-rotation.scm
b/modules/shepherd/service/log-rotation.scm
index 0145b9a..66721ad 100644
--- a/modules/shepherd/service/log-rotation.scm
+++ b/modules/shepherd/service/log-rotation.scm
@@ -25,7 +25,9 @@
timer-trigger-action)
#:autoload (shepherd service) (service
service-logger
- for-each-service)
+ service-canonical-name
+ for-each-service
+ action)
#:autoload (shepherd system) (%gzip-program %zstd-program)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
@@ -248,7 +250,7 @@ only if the service that mounts the file system that hosts
log files is up."
(local-output (l10n "Deleting old log file '~a'.") old)
(delete-file old)))))
- (define action
+ (define rotation
(lambda ()
(rotate-service-logs rotate
#:compression compression
@@ -262,9 +264,29 @@ only if the service that mounts the file system that hosts
log files is up."
rotation-size-threshold))
external-log-files)))
+ (define files-action
+ (action 'files
+ (lambda _
+ (for-each-service (lambda (service)
+ (match (service-logger service)
+ (#f #f)
+ (logger
+ (let ((file (logger-file logger)))
+ (when file
+ (format #t "~a\t~a~%"
+ file (service-canonical-name
+ service))))))))
+ (for-each (lambda (file)
+ ;; TRANSLATORS: "External" here refers to "external
+ ;; log files".
+ (format #t (l10n "~a\t(external)~%")
+ file))
+ external-log-files))
+ (l10n "List the log files subject to rotation.")))
+
(service provision
- #:start (make-timer-constructor event action)
+ #:start (make-timer-constructor event rotation)
#:stop (make-timer-destructor)
- #:actions (list timer-trigger-action)
+ #:actions (list timer-trigger-action files-action)
#:documentation
(l10n "Periodically rotate the log files of services.")))
diff --git a/tests/services/log-rotation.sh b/tests/services/log-rotation.sh
index 15e3e9e..62f2b7b 100644
--- a/tests/services/log-rotation.sh
+++ b/tests/services/log-rotation.sh
@@ -70,6 +70,11 @@ $herd start log-rotation
sleep 0.5
+for file in "$service_log1" "$service_log2" "$external_log"
+do
+ $herd files log-rotation | grep "$file"
+done
+
test -f "$service_log1"
test -f "$service_log2"
echo "This is an external log file." > "$external_log"
- [shepherd] branch devel updated (25ef327 -> b8fcd5a), Ludovic Courtès, 2024/06/15
- [shepherd] 05/06: herd: Distinguish ‘herd status root’ from ‘herd status’., Ludovic Courtès, 2024/06/15
- [shepherd] 06/06: service: Value of ‘root’ service is now a <process>., Ludovic Courtès, 2024/06/15
- [shepherd] 04/06: shepherd: PID 1 logs to /dev/log by default, again., Ludovic Courtès, 2024/06/15
- [shepherd] 01/06: log-rotation: Add ‘files’ action.,
Ludovic Courtès <=
- [shepherd] 02/06: logger: File logger keeps an absolute log file name., Ludovic Courtès, 2024/06/15
- [shepherd] 03/06: shepherd: Use a file logger for the ‘root’ service., Ludovic Courtès, 2024/06/15