all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 63082@debbugs.gnu.org
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: bug#63082: [PATCH v3 08/16] services: mpd: Log to syslog by default.
Date: Fri,  5 May 2023 14:29:03 -0400	[thread overview]
Message-ID: <6f7567fe5433abc84119626c93a6504ba581bdf7.1683299529.git.maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <cover.1683299528.git.maxim.cournoyer@gmail.com>

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.
---
 doc/guix.texi          | 17 +++++-----
 gnu/services/audio.scm | 74 ++++++++++++++++++++++++++++--------------
 2 files changed, 57 insertions(+), 34 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 200f6d019c..253b8f113b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -33610,10 +33610,10 @@ Audio Services
 @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.
 
-@item @code{log-file} (default: @code{"/var/log/mpd/log"}) (type: maybe-string)
-The location of the log file.  Set to @code{syslog} to use the local
-syslog daemon or @code{%unset-value} to omit this directive from the
-configuration file.
+@item @code{log-file} (type: maybe-string)
+The location of the log file.  Unless specified, logs are sent to the
+local syslog daemon.  Alternatively, a log file name can be specified,
+for example @file{/var/log/mpd.log}.
 
 @item @code{log-level} (type: maybe-string)
 Supress any messages below this threshold.  The available values, in
@@ -33884,11 +33884,10 @@ Audio Services
 How much detail to include in logs, possible values: @code{0} to
 @code{7}.
 
-@item @code{log-to} (default: @code{"/var/log/mympd/log"}) (type: string-or-symbol)
-Where to send logs.  By default, the service logs to
-@file{/var/log/mympd.log}.  The alternative is @code{'syslog}, which
-sends output to the running syslog service under the @samp{daemon}
-facility.
+@item @code{log-to} (type: maybe-string)
+Where to send logs.  Unless specified, the service logs to the local
+syslog service under the @samp{daemon} facility.  Alternatively, a log
+file name can be specified, for example @file{/var/log/mympd.log}.
 
 @item @code{lualibs} (default: @code{"all"}) (type: maybe-string)
 See
diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm
index 6e57bf5cba..c1295837b6 100644
--- a/gnu/services/audio.scm
+++ b/gnu/services/audio.scm
@@ -229,6 +229,18 @@ (define (mpd-group-sanitizer value)
     (warning (G_ "'group' in <mpd-configuration> is obsolete; ignoring~%")))
   #f)
 
+(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.
@@ -402,10 +414,11 @@ (define-configuration mpd-configuration
    empty-serializer)
 
   (log-file
-   (maybe-string "/var/log/mpd/log")
-   "The location of the log file. Set to @code{syslog} to use the
-local syslog daemon or @code{%unset-value} to omit this directive
-from the configuration file.")
+   maybe-string
+   "The location of the log file.  Unless specified, logs are sent to the
+local syslog daemon.  Alternatively, a log file name can be specified, for
+example @file{/var/log/mpd.log}."
+   (sanitizer mpd-log-file-sanitizer))
 
   (log-level
    maybe-string
@@ -562,7 +575,11 @@ (define (mpd-shepherd-service config)
           (username (user-account-name user)))
       (shepherd-service
        (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))
        (start
         (with-imported-modules (source-module-closure
@@ -683,6 +700,15 @@ (define (mympd-group-sanitizer value)
     (warning (G_ "'group' in <mympd-configuration> is obsolete; ignoring~%")))
   #f)
 
+(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))))
+
 ;;;
 
 
@@ -749,10 +775,11 @@ (define-configuration/no-serialization mympd-configuration
    "How much detail to include in logs, possible values: @code{0} to @code{7}.")
 
   (log-to
-   (string-or-symbol "/var/log/mympd/log")
-   "Where to send logs. By default, the service logs to
-@file{/var/log/mympd.log}. The alternative is @code{'syslog}, which
-sends output to the running syslog service under the @samp{daemon} facility."
+   maybe-string
+   "Where to send logs.  Unless specified, the service logs to the local
+syslog service under the @samp{daemon} facility.  Alternatively, a log file
+name can be specified, for example @file{/var/log/mympd.log}."
+   (sanitizer mympd-log-to-sanitizer)
    empty-serializer)
 
   (lualibs
@@ -849,9 +876,9 @@ (define (mympd-shepherd-service config)
     (shepherd-service
      (documentation "Run the myMPD daemon.")
      (requirement `(loopback user-processes
-                             ,@(if (eq? log-to 'syslog)
-                                   '(syslog)
-                                   '())
+                             ,@(if (maybe-value-set? log-to)
+                                   '()
+                                   '(syslogd))
                              ,@shepherd-requirement))
      (provision '(mympd))
      (start
@@ -867,16 +894,12 @@ (define (mympd-shepherd-service config)
                   (unless (file-exists? directory)
                     (mkdir-p/perms directory user #o755)))
 
-                (for-each
-                 init-directory
-                 '#$(map dirname
-                         ;; XXX: Delete the potential 'syslog log-file value,
-                         ;; which is not a directory.
-                         (delete 'syslog
-                                 (filter-map maybe-value
-                                             (list log-to
-                                                   work-directory
-                                                   cache-directory))))))
+                (for-each init-directory
+                          '#$(map dirname (filter-map maybe-value
+                                                      (list log-to
+                                                            work-directory
+                                                            cache-directory)))))
+
               (make-forkexec-constructor
                `(#$(file-append package "/bin/mympd")
                  "--user" #$username
@@ -885,7 +908,7 @@ (define (mympd-shepherd-service config)
                  "--cachedir" #$cache-directory)
                #:environment-variables
                (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)
   (match-record config <mympd-configuration>
@@ -893,8 +916,9 @@ (define (mympd-accounts config)
     (list user)))
 
 (define (mympd-log-rotation config)
-  (match-record config <mympd-configuration> (log-to)
-    (if (string? log-to)
+  (match-record config <mympd-configuration>
+    (log-to)
+    (if (maybe-value-set? log-to)
         (list (log-rotation
                (files (list log-to))))
         '())))
-- 
2.39.2





  parent reply	other threads:[~2023-05-05 18:30 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26  2:58 bug#63082: mpd defaul configuration does not work ('No database' error) Maxim Cournoyer
2023-04-26  3:11 ` Maxim Cournoyer
2023-04-26 18:28   ` Liliana Marie Prikler
2023-04-28 14:26 ` bug#63082: [PATCH 00/17] Improve out-of-the-box experience with mpd-service-type Maxim Cournoyer
2023-04-28 14:26   ` bug#63082: [PATCH 01/17] services: mpd: Add an 'update' action to trigger a database update Maxim Cournoyer
2023-04-28 14:26   ` bug#63082: [PATCH 02/17] services: mpd: Streamline mpd-user-sanitizer and mympd-user-sanitizer Maxim Cournoyer
2023-04-28 14:26   ` bug#63082: [PATCH 03/17] services: mpd: Rename %set-user-group to set-user-group Maxim Cournoyer
2023-04-28 14:26   ` bug#63082: [PATCH 04/17] services: mpd: Obsolete the 'group' field Maxim Cournoyer
2023-04-28 21:50     ` Bruno Victal
2023-04-29  1:15       ` Maxim Cournoyer
2023-04-29 12:12         ` Bruno Victal
2023-04-29 17:12           ` Maxim Cournoyer
2023-04-29  6:26     ` Liliana Marie Prikler
2023-04-29  6:35       ` Liliana Marie Prikler
2023-04-29 17:09         ` Maxim Cournoyer
2023-04-29 17:16         ` Maxim Cournoyer
2023-04-29 22:07           ` Liliana Marie Prikler
2023-05-01  1:07             ` Maxim Cournoyer
2023-05-01  6:13               ` Liliana Marie Prikler
2023-05-03  1:53                 ` Maxim Cournoyer
2023-04-28 14:26   ` bug#63082: [PATCH 05/17] services: mpd: List log-level in decreasing verbosity order in doc Maxim Cournoyer
2023-04-28 14:26   ` bug#63082: [PATCH 06/17] services: mympd: Fix log file name Maxim Cournoyer
2023-04-28 21:53     ` Bruno Victal
2023-04-29  1:49       ` Maxim Cournoyer
2023-04-29  1:56         ` Bruno Victal
2023-04-28 14:27   ` bug#63082: [PATCH 07/17] services: mpd: Log to syslog by default Maxim Cournoyer
2023-04-28 22:02     ` Bruno Victal
2023-04-29 16:06       ` Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 08/17] services: mpd: Only rotate log when a log file is specified Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 09/17] services: mpd: Let Shepherd effect the user/group change Maxim Cournoyer
2023-04-28 22:11     ` Bruno Victal
2023-04-29 16:52       ` Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 10/17] system: accounts: Export <user-account> Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 11/17] services: mpd: Warn when the MPD user is not in the "audio" group Maxim Cournoyer
2023-04-29  6:29     ` Liliana Marie Prikler
2023-04-29 17:10       ` Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 12/17] services: mpd: Auto-detect mpd-output mixer type by default Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 13/17] services: mpd: Fix indentation Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 14/17] services: mpd: Obsolete 'environment-variables' field Maxim Cournoyer
2023-04-28 22:17     ` Bruno Victal
2023-04-29 17:04       ` Maxim Cournoyer
2023-04-29 17:23         ` Bruno Victal
2023-05-03  1:44           ` Maxim Cournoyer
2023-05-04 16:21             ` Bruno Victal
2023-05-05 14:44               ` Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 15/17] services: mpd: Provision a default cache directory and set HOME Maxim Cournoyer
2023-04-28 22:22     ` Bruno Victal
2023-04-29 17:07       ` Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 16/17] services: mpd: Update basic example Maxim Cournoyer
2023-04-28 14:27   ` bug#63082: [PATCH 17/17] services: Avoid 'delete' overrides warning in audio module Maxim Cournoyer
2023-04-29 17:21 ` bug#63082: [PATCH v2 00/16] Improve out-of-the-box experience with mpd-service-type Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 01/16] services: mpd: Add an 'update' action to trigger a database update Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 02/16] services: mpd: Streamline mpd-user-sanitizer and mympd-user-sanitizer Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 03/16] services: mpd: Rename %set-user-group to set-user-group Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 04/16] services: mpd: Obsolete the 'group' field Maxim Cournoyer
2023-05-05  0:38     ` Bruno Victal
2023-05-05 15:09       ` bug#63082: mpd defaul configuration does not work ('No database' error) Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 05/16] services: mpd: List log-level in decreasing verbosity order in doc Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 06/16] services: mpd; Refactor start slot directory initialization Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 07/16] services: mpd: Log to syslog by default Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 08/16] services: mpd: Do not rotate logs when using syslog Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 09/16] services: mpd: Let Shepherd effect the user/group change Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 10/16] system: accounts: Export <user-account> Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 11/16] services: mpd: Warn when the MPD user is not in the "audio" group Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 12/16] services: mpd: Auto-detect mpd-output mixer type by default Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 13/16] services: mpd: Obsolete 'environment-variables' field Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 14/16] services: mpd: Provision a default cache directory and set HOME Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 15/16] services: mpd: Update basic example Maxim Cournoyer
2023-04-29 17:21   ` bug#63082: [PATCH v2 16/16] services: Avoid 'delete' overrides warning in audio module Maxim Cournoyer
2023-05-05 18:28 ` bug#63082: [PATCH v3 00/16] Improve out-of-the-box experience with mpd-service-type Maxim Cournoyer
2023-05-05 18:28   ` bug#63082: [PATCH v3 01/16] services: mpd: Add auto-update? field to mpd-configuration Maxim Cournoyer
2023-05-05 18:28   ` bug#63082: [PATCH v3 02/16] services: mpd: Add an 'update' action to trigger a database update Maxim Cournoyer
2023-05-24 16:00     ` Bruno Victal
2023-07-25 20:48       ` bug#63082: mpd defaul configuration does not work ('No database' error) Maxim Cournoyer
2023-07-26 14:02         ` Bruno Victal
2023-07-26 16:12           ` Maxim Cournoyer
2023-05-05 18:28   ` bug#63082: [PATCH v3 03/16] services: mpd: Streamline mpd-user-sanitizer and mympd-user-sanitizer Maxim Cournoyer
2023-05-05 18:28   ` bug#63082: [PATCH v3 04/16] services: mpd: Rename %set-user-group to set-user-group Maxim Cournoyer
2023-05-05 19:42     ` Liliana Marie Prikler
2023-05-07  2:37       ` Maxim Cournoyer
2023-05-24 16:09     ` Bruno Victal
2023-05-05 18:29   ` bug#63082: [PATCH v3 05/16] services: mpd: Obsolete the 'group' field Maxim Cournoyer
2023-05-05 19:51     ` Liliana Marie Prikler
2023-05-07  2:55       ` Maxim Cournoyer
2023-05-07  5:35         ` Liliana Marie Prikler
2023-05-07 18:12           ` Maxim Cournoyer
2023-05-07 18:31             ` Liliana Marie Prikler
2023-05-08  1:05               ` Maxim Cournoyer
2023-05-08 17:21                 ` Liliana Marie Prikler
2023-05-05 18:29   ` bug#63082: [PATCH v3 06/16] services: mpd: List log-level in decreasing verbosity order in doc Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 07/16] services: mpd; Refactor start slot directory initialization Maxim Cournoyer
2023-05-24 16:26     ` Bruno Victal
2023-07-25 20:07       ` bug#63082: mpd defaul configuration does not work ('No database' error) Maxim Cournoyer
2023-05-05 18:29   ` Maxim Cournoyer [this message]
2023-05-05 18:29   ` bug#63082: [PATCH v3 09/16] services: mpd: Do not rotate logs when using syslog Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 10/16] services: mpd: Let Shepherd effect the user/group change Maxim Cournoyer
2023-05-24 16:41     ` Bruno Victal
2023-07-25 19:39       ` bug#63082: mpd defaul configuration does not work ('No database' error) Maxim Cournoyer
2023-07-26 15:54       ` bug#63082: [PATCH v3 10/16] services: mpd: Let Shepherd effect the user/group change Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 11/16] system: accounts: Export <user-account> Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 12/16] services: mpd: Warn when the MPD user is not in the "audio" group Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 13/16] services: mpd: Auto-detect mpd-output mixer type by default Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 14/16] services: mpd: Provision a default cache directory and set HOME Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 15/16] services: mpd: Update basic example Maxim Cournoyer
2023-05-05 18:29   ` bug#63082: [PATCH v3 16/16] services: Avoid 'delete' overrides warning in audio module Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f7567fe5433abc84119626c93a6504ba581bdf7.1683299529.git.maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=63082@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.