1
Fork 0
mirror of https://https.git.savannah.gnu.org/git/guix.git/ synced 2025-07-13 10:30:43 +02:00

services: fstrim: Turn into a Shepherd timer.

* gnu/services/linux.scm (mcron-time?): Remove.
(shepherd-calendar-event?): New procedure.
(fstrim-configuration)[schedule]: Change type to
‘shepherd-calendar-event’ and update docstring.
(fstrim-mcron-job): Rename to…
(fstrim-shepherd-services): … this.  Return a list of Shepherd services.
(fstrim-service-type): Adjust accordingly.
* doc/guix.texi (Linux Services): Update.

Reviewed-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Change-Id: I9a7433cb15a1f4600470a915769d612e6e644dd8
This commit is contained in:
Ludovic Courtès 2025-03-13 10:15:52 +01:00
parent 71ae6f2a19
commit 465ce8c6a6
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 36 additions and 28 deletions

View file

@ -42127,6 +42127,7 @@ in its default configuration with:
@end defvar @end defvar
@c %start of fragment @c %start of fragment
@deftp {Data Type} fstrim-configuration @deftp {Data Type} fstrim-configuration
Available @code{fstrim-configuration} fields are: Available @code{fstrim-configuration} fields are:
@ -42134,11 +42135,11 @@ Available @code{fstrim-configuration} fields are:
@item @code{package} (default: @code{util-linux}) (type: file-like) @item @code{package} (default: @code{util-linux}) (type: file-like)
The package providing the @command{fstrim} command. The package providing the @command{fstrim} command.
@item @code{schedule} (default: @code{"0 0 * * 0"}) (type: mcron-time) @item @code{schedule} (default: @code{"0 0 * * 0"}) (type: Shepherd calendar event)
Schedule for launching @command{fstrim}. This can be a procedure, a Schedule for launching @command{fstrim}, expressed as a string in
list or a string. For additional information, see @ref{Guile traditional cron syntax or as a gexp evaluating to a Shepherd calendar
Syntax,,Job specification,mcron,the mcron manual}. By default this is event (@pxref{Timers,,, shepherd,The GNU Shepherd Manual}). By default
set to run weekly on Sunday at 00:00. this is set to run weekly on Sunday at 00:00.
@item @code{listed-in} (default: @code{'("/etc/fstab" "/proc/self/mountinfo")}) (type: maybe-list-of-strings) @item @code{listed-in} (default: @code{'("/etc/fstab" "/proc/self/mountinfo")}) (type: maybe-list-of-strings)
List of files in fstab or kernel mountinfo format. All missing or empty List of files in fstab or kernel mountinfo format. All missing or empty
@ -42157,7 +42158,10 @@ Extra options to append to @command{fstrim} (run @samp{man fstrim} for
more information). more information).
@end table @end table
@end deftp @end deftp
@c %end of fragment @c %end of fragment
@cindex modprobe @cindex modprobe

View file

@ -34,7 +34,6 @@
#:use-module (gnu services admin) #:use-module (gnu services admin)
#:use-module (gnu services base) #:use-module (gnu services base)
#:use-module (gnu services configuration) #:use-module (gnu services configuration)
#:use-module (gnu services mcron)
#:use-module (gnu services shepherd) #:use-module (gnu services shepherd)
#:use-module (gnu packages linux) #:use-module (gnu packages linux)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
@ -196,8 +195,8 @@ representation."
;;; fstrim ;;; fstrim
;;; ;;;
(define (mcron-time? x) (define (shepherd-calendar-event? x)
(or (procedure? x) (string? x) (list? x))) (or (string? x) (gexp? x)))
(define-maybe list-of-strings (prefix fstrim-)) (define-maybe list-of-strings (prefix fstrim-))
@ -216,11 +215,11 @@ representation."
"The package providing the @command{fstrim} command." "The package providing the @command{fstrim} command."
empty-serializer) empty-serializer)
(schedule (schedule
(mcron-time "0 0 * * 0") (shepherd-calendar-event "0 0 * * 0")
"Schedule for launching @command{fstrim}. This can be a procedure, a list "Schedule for launching @command{fstrim}, expressed as a string in
or a string. For additional information, see @ref{Guile Syntax,, traditional cron syntax or as a gexp evaluating to a Shepherd calendar
Job specification, mcron, the mcron manual}. By default this is set to run event (@pxref{Timers,,, shepherd, The GNU Shepherd Manual}). By default this
weekly on Sunday at 00:00." is set to run weekly on Sunday at 00:00."
empty-serializer) empty-serializer)
;; The following are fstrim-related options. ;; The following are fstrim-related options.
(listed-in (listed-in
@ -251,26 +250,31 @@ more information)."
rcons rcons
fstrim-configuration-fields)) fstrim-configuration-fields))
(define (fstrim-mcron-job config) (define (fstrim-shepherd-services config)
(match-record config <fstrim-configuration> (package schedule) (match-record config <fstrim-configuration>
#~(job (package schedule)
;; Note: The “if” below is to ensure that (list (shepherd-service
;; lists are ungexp'd correctly since @var{schedule} (provision '(fstrim))
;; can be either a procedure, a string or a list. (requirement '(user-processes))
#$(if (list? schedule) (modules '((shepherd service timer)))
#~'(#$@schedule) (start #~(make-timer-constructor
schedule) #$(if (string? schedule)
(lambda () #~(cron-string->calendar-event #$schedule)
(system* #$(file-append package "/sbin/fstrim") schedule)
#$@(serialize-fstrim-configuration config))) (command
"fstrim"))) (list #$(file-append package "/sbin/fstrim")
#$@(serialize-fstrim-configuration config)))
#:wait-for-termination? #t))
(stop #~(make-timer-destructor))
(documentation "Periodically run the 'fstrim' command.")
(actions (list shepherd-trigger-action))))))
(define fstrim-service-type (define fstrim-service-type
(service-type (service-type
(name 'fstrim) (name 'fstrim)
(extensions (extensions
(list (service-extension mcron-service-type (list (service-extension shepherd-root-service-type
(compose list fstrim-mcron-job)))) fstrim-shepherd-services)))
(description "Discard unused blocks from file systems.") (description "Discard unused blocks from file systems.")
(default-value (fstrim-configuration)))) (default-value (fstrim-configuration))))