me
/
guix
Archived
1
0
Fork 0

services: mpd: Log to syslog by default.

Rationale: the tristate value was awkward to deal with, the default log file
name was odd (/var/log/mpd/log) and it required special attention to create
the 'mpd' parent directory as root and chowning it to the MPD user.  It also
didn't match the default behavior of MPD, which is to log to systemd or syslog
unless a log file is specified.

* gnu/services/audio.scm (mpd-log-file-sanitizer): New procedure.
(mpd-configuration) [log-file]: Remove default maybe value.  Add sanitizer.
(mpd-shepherd-service): Validate the log file parent directory exists and has
the right permissions.  Conditionally add syslogd to requirements.
(mympd-log-to-sanitizer): New procedure.
(mympd-configuration) [log-to]: Change type to maybe-string.  Update doc and
add sanitizer.
(mympd-shepherd-service) [requirement]: Fix to use syslogd.  Adjust
accordingly.
[start] Adjust accordingly.
(mympd-log-rotation): Check log-to via maybe-value-set?.
* doc/guix.texi (Audio Services): Update doc.
Maxim Cournoyer 2023-04-26 23:47:51 -04:00
parent a5d611c19b
commit 131746885c
No known key found for this signature in database
GPG Key ID: 1260E46482E63562
2 changed files with 56 additions and 35 deletions

View File

@ -34288,10 +34288,10 @@ will depend on.
@item @code{environment-variables} (default: @code{'("PULSE_CLIENTCONFIG=/etc/pulse/client.conf" "PULSE_CONFIG=/etc/pulse/daemon.conf")}) (type: list-of-strings) @item @code{environment-variables} (default: @code{'("PULSE_CLIENTCONFIG=/etc/pulse/client.conf" "PULSE_CONFIG=/etc/pulse/daemon.conf")}) (type: list-of-strings)
A list of strings specifying environment variables. A list of strings specifying environment variables.
@item @code{log-file} (default: @code{"/var/log/mpd/log"}) (type: maybe-string) @item @code{log-file} (type: maybe-string)
The location of the log file. Set to @code{syslog} to use the local The location of the log file. Unless specified, logs are sent to the
syslog daemon or @code{%unset-value} to omit this directive from the local syslog daemon. Alternatively, a log file name can be specified,
configuration file. for example @file{/var/log/mpd.log}.
@item @code{log-level} (type: maybe-string) @item @code{log-level} (type: maybe-string)
Supress any messages below this threshold. The available values, in Supress any messages below this threshold. The available values, in
@ -34565,11 +34565,10 @@ HTTP port to listen on.
How much detail to include in logs, possible values: @code{0} to How much detail to include in logs, possible values: @code{0} to
@code{7}. @code{7}.
@item @code{log-to} (default: @code{"/var/log/mympd/log"}) (type: string-or-symbol) @item @code{log-to} (type: maybe-string)
Where to send logs. By default, the service logs to Where to send logs. Unless specified, the service logs to the local
@file{/var/log/mympd.log}. The alternative is @code{'syslog}, which syslog service under the @samp{daemon} facility. Alternatively, a log
sends output to the running syslog service under the @samp{daemon} file name can be specified, for example @file{/var/log/mympd.log}.
facility.
@item @code{lualibs} (default: @code{"all"}) (type: maybe-string) @item @code{lualibs} (default: @code{"all"}) (type: maybe-string)
See See

View File

@ -253,6 +253,18 @@ user-group instead~%"))
(else (else
(configuration-field-error #f 'group value)))) (configuration-field-error #f 'group value))))
(define (mpd-log-file-sanitizer value)
(match value
(%unset-value
;; XXX: While leaving the 'sys_log' option out of the mpd.conf file is
;; supposed to cause logging to happen via systemd (elogind provides a
;; compatible interface), this doesn't work (nothing gets logged); use
;; syslog instead.
"syslog")
((? string?)
value)
(_ (configuration-field-error #f 'log-file value))))
;;; ;;;
;; Generic MPD plugin record, lists only the most prevalent fields. ;; Generic MPD plugin record, lists only the most prevalent fields.
@ -425,10 +437,11 @@ will depend on."
empty-serializer) empty-serializer)
(log-file (log-file
(maybe-string "/var/log/mpd/log") maybe-string
"The location of the log file. Set to @code{syslog} to use the "The location of the log file. Unless specified, logs are sent to the
local syslog daemon or @code{%unset-value} to omit this directive local syslog daemon. Alternatively, a log file name can be specified, for
from the configuration file.") example @file{/var/log/mpd.log}."
(sanitizer mpd-log-file-sanitizer))
(log-level (log-level
maybe-string maybe-string
@ -585,7 +598,11 @@ appended to the configuration.")
(username (user-account-name user))) (username (user-account-name user)))
(shepherd-service (shepherd-service
(documentation "Run the MPD (Music Player Daemon)") (documentation "Run the MPD (Music Player Daemon)")
(requirement `(user-processes loopback ,@shepherd-requirement)) (requirement `(user-processes loopback
,@(if (string=? "syslog" log-file)
'(syslogd)
'())
,@shepherd-requirement))
(provision '(mpd)) (provision '(mpd))
(start (start
(with-imported-modules (source-module-closure (with-imported-modules (source-module-closure
@ -721,8 +738,15 @@ user-group instead~%"))
(name value))) (name value)))
(else (else
(configuration-field-error #f 'group value)))) (configuration-field-error #f 'group value))))
;;;
(define (mympd-log-to-sanitizer value)
(match value
('syslog
(warning (G_ "syslog symbol value for 'log-to' is deprecated~%"))
%unset-value)
((or %unset-value (? string?))
value)
(_ (configuration-field-error #f 'log-to value))))
;; XXX: The serialization procedures are insufficient since we require ;; XXX: The serialization procedures are insufficient since we require
;; access to multiple fields at once. ;; access to multiple fields at once.
@ -787,10 +811,11 @@ will depend on."
"How much detail to include in logs, possible values: @code{0} to @code{7}.") "How much detail to include in logs, possible values: @code{0} to @code{7}.")
(log-to (log-to
(string-or-symbol "/var/log/mympd/log") maybe-string
"Where to send logs. By default, the service logs to "Where to send logs. Unless specified, the service logs to the local
@file{/var/log/mympd.log}. The alternative is @code{'syslog}, which syslog service under the @samp{daemon} facility. Alternatively, a log file
sends output to the running syslog service under the @samp{daemon} facility." name can be specified, for example @file{/var/log/mympd.log}."
(sanitizer mympd-log-to-sanitizer)
empty-serializer) empty-serializer)
(lualibs (lualibs
@ -887,9 +912,9 @@ prompting a pin from the user.")
(shepherd-service (shepherd-service
(documentation "Run the myMPD daemon.") (documentation "Run the myMPD daemon.")
(requirement `(loopback user-processes (requirement `(loopback user-processes
,@(if (eq? log-to 'syslog) ,@(if (maybe-value-set? log-to)
'(syslog) '()
'()) '(syslogd))
,@shepherd-requirement)) ,@shepherd-requirement))
(provision '(mympd)) (provision '(mympd))
(start (start
@ -905,16 +930,12 @@ prompting a pin from the user.")
(unless (file-exists? directory) (unless (file-exists? directory)
(mkdir-p/perms directory user #o755))) (mkdir-p/perms directory user #o755)))
(for-each (for-each init-directory
init-directory '#$(map dirname (filter-map maybe-value
'#$(map dirname
;; XXX: Delete the potential 'syslog log-file value,
;; which is not a directory.
(delete 'syslog
(filter-map maybe-value
(list log-to (list log-to
work-directory work-directory
cache-directory)))))) cache-directory)))))
(make-forkexec-constructor (make-forkexec-constructor
`(#$(file-append package "/bin/mympd") `(#$(file-append package "/bin/mympd")
"--user" #$username "--user" #$username
@ -923,7 +944,7 @@ prompting a pin from the user.")
"--cachedir" #$cache-directory) "--cachedir" #$cache-directory)
#:environment-variables #:environment-variables
(list #$(format #f "MYMPD_LOGLEVEL=~a" log-level)) (list #$(format #f "MYMPD_LOGLEVEL=~a" log-level))
#:log-file #$(if (string? log-to) log-to #f))))))))) #:log-file #$(maybe-value log-to)))))))))
(define (mympd-accounts config) (define (mympd-accounts config)
(match-record config <mympd-configuration> (user group) (match-record config <mympd-configuration> (user group)
@ -934,8 +955,9 @@ prompting a pin from the user.")
(list user group)))) (list user group))))
(define (mympd-log-rotation config) (define (mympd-log-rotation config)
(match-record config <mympd-configuration> (log-to) (match-record config <mympd-configuration>
(if (string? log-to) (log-to)
(if (maybe-value-set? log-to)
(list (log-rotation (list (log-rotation
(files (list log-to)))) (files (list log-to))))
'()))) '())))