From: Liliana Marie Prikler <liliana.prikler@gmail.com>
To: 54986@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
"Maxime Devos" <maximedevos@telenet.be>
Subject: [bug#54986] [PATCH v3 2/2] services: mpd: Support socket activation.
Date: Sat, 23 Apr 2022 16:39:59 +0200 [thread overview]
Message-ID: <3105812906c619735df4a5f476c1c822c63bfb15.camel@gmail.com> (raw)
In-Reply-To: <9d4cc9d3ebb05d2aabf8f06e1890efe9b0b9a849.camel@gmail.com>
* gnu/services/audio.scm (<mpd-endpoint>): New record.
(<mpd-configuration>)[port, address]: Removed fields.
[endpoints]: New field.
(sanitize-mpd-endpoints, mpd-configuration-shepherd-endpoints): New variables.
(mpd-shepherd-service): Use mpd-configuration-shepherd-endpoints.
* doc/guix.texi (Music Player Daemon): Document it.
---
doc/guix.texi | 23 ++++++++--
gnu/services/audio.scm | 98 +++++++++++++++++++++++++++++++++---------
2 files changed, 97 insertions(+), 24 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 30cc3b6d45..d5b9de0de2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -32192,15 +32192,30 @@ The location of the file that stores current MPD's state.
@item @code{sticker-file} (default: @code{"~/.mpd/sticker.sql"})
The location of the sticker database.
-@item @code{port} (default: @code{"6600"})
-The port to run mpd on.
+@item @code{endpoints} (default: @code{(list (mpd-endpoint))})
+The endpoints to bind MPD to. This can be an mpd-endpoint (see below)
+or a list of shepherd endpoints. If using shepherd endpoints, MPD
+will be spawned as a systemd-style service rather than as a
+forkexec-style one. This delays the start of MPD until the first client
+connects.
+
+@item @code{outputs} (default: @code{"(list (mpd-output))"})
+The audio outputs that MPD can use. By default this is a single output using pulseaudio.
+
+@end table
+@end deftp
+
+@deftp {Data Type} mpd-endpoint
+Data type representing the configuration of @command{mpd}.
+
+@table @asis
@item @code{address} (default: @code{"any"})
The address that mpd will bind to. To use a Unix domain socket,
an absolute path can be specified here.
-@item @code{outputs} (default: @code{"(list (mpd-output))"})
-The audio outputs that MPD can use. By default this is a single output using pulseaudio.
+@item @code{port} (default: @code{"6600"})
+The port to run mpd on.
@end table
@end deftp
diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm
index c60053f33c..6e8fd460a1 100644
--- a/gnu/services/audio.scm
+++ b/gnu/services/audio.scm
@@ -20,6 +20,8 @@
(define-module (gnu services audio)
#:use-module (guix gexp)
+ #:use-module (guix diagnostics)
+ #:use-module (guix i18n)
#:use-module (gnu services)
#:use-module (gnu services shepherd)
#:use-module (gnu system shadow)
@@ -28,8 +30,14 @@ (define-module (gnu services audio)
#:use-module (guix records)
#:use-module (ice-9 match)
#:use-module (ice-9 format)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-34)
+ #:use-module (srfi srfi-35)
#:export (mpd-output
mpd-output?
+ mpd-endpoint
+ mpd-endpoint?
mpd-configuration
mpd-configuration?
mpd-service-type))
@@ -59,6 +67,30 @@ (define-record-type* <mpd-output>
(extra-options mpd-output-extra-options
(default '())))
+(define-record-type* <mpd-endpoint>
+ mpd-endpoint make-mpd-endpoint
+ mpd-endpoint?
+ (address mpd-endpoint-address (default "any"))
+ (port mpd-endpoint-port (default "6600")))
+
+(define-with-syntax-properties (sanitize-mpd-endpoints (endpoints properties))
+ (match endpoints
+ ((? mpd-endpoint? endpoint) (list endpoint))
+ (((? mpd-endpoint?)) endpoints)
+ (((? mpd-endpoint?) . _)
+ (raise (make-compound-condition
+ (condition (&message
+ (message
+ (G_ "\
+<mpd-endpoint> is mutually exclusive with other endpoints."))))
+ (condition (&error-location
+ (location (source-properties->location properties))))
+ (condition (&fix-hint
+ (hint "\
+Make sure you only need one endpoint or use shepherd endpoints instead."))))))
+ (((? shepherd-endpoint?) . (? (cute every shepherd-endpoint? <>)))
+ endpoints)))
+
(define-record-type* <mpd-configuration>
mpd-configuration make-mpd-configuration
mpd-configuration?
@@ -74,10 +106,9 @@ (define-record-type* <mpd-configuration>
(default "~/.mpd/state"))
(sticker-file mpd-configuration-sticker-file
(default "~/.mpd/sticker.sql"))
- (port mpd-configuration-port
- (default "6600"))
- (address mpd-configuration-address
- (default "any"))
+ (endpoints mpd-configuration-endpoints ; list of <shepherd-endpoint>
+ (default (list (mpd-endpoint))) ; | <mpd-endpoint>
+ (sanitize sanitize-mpd-endpoints))
(outputs mpd-configuration-outputs
(default (list (mpd-output)))))
@@ -124,9 +155,12 @@ (define (mpd-config->file config)
("playlist_directory" ,mpd-configuration-playlist-dir)
("db_file" ,mpd-configuration-db-file)
("state_file" ,mpd-configuration-state-file)
- ("sticker_file" ,mpd-configuration-sticker-file)
- ("port" ,mpd-configuration-port)
- ("bind_to_address" ,mpd-configuration-address))))))
+ ("sticker_file" ,mpd-configuration-sticker-file)))
+ (match (mpd-configuration-endpoints config)
+ (($ <mpd-endpoint> address port)
+ `(("bind_to_address" ,address)
+ ("port" ,port)))
+ (_ '())))))
(define (mpd-file-name config file)
"Return a path in /var/run/mpd/ that is writable
@@ -135,24 +169,48 @@ (define (mpd-file-name config file)
(mpd-configuration-user config)
"/" file))
+(define (mpd-configuration-shepherd-endpoints config)
+ "Return @code{(mpd-configuration-endpoints config)}"
+ (let ((endpoints (mpd-configuration-endpoints config)))
+ (match endpoints
+ (((? shepherd-endpoint?) . _) endpoints)
+ (_ #f))))
+
(define (mpd-shepherd-service config)
(shepherd-service
(documentation "Run the MPD (Music Player Daemon)")
(requirement '(user-processes))
(provision '(mpd))
- (start #~(make-forkexec-constructor
- (list #$(file-append mpd "/bin/mpd")
- "--no-daemon"
- #$(mpd-config->file config))
- #:environment-variables
- ;; Required to detect PulseAudio when run under a user account.
- (list (string-append
- "XDG_RUNTIME_DIR=/run/user/"
- (number->string
- (passwd:uid
- (getpwnam #$(mpd-configuration-user config))))))
- #:log-file #$(mpd-file-name config "log")))
- (stop #~(make-kill-destructor))))
+ (start (if (mpd-configuration-shepherd-endpoints config)
+ #~(make-systemd-constructor
+ (list #$(file-append mpd "/bin/mpd")
+ "--systemd"
+ #$(mpd-config->file config))
+ (list #$@(map shepherd-endpoint->sexp
+ (mpd-configuration-shepherd-endpoints config)))
+ #:environment-variables
+ ;; Required to detect PulseAudio when run under a user account.
+ (list (string-append
+ "XDG_RUNTIME_DIR=/run/user/"
+ (number->string
+ (passwd:uid
+ (getpwnam #$(mpd-configuration-user config))))))
+ #:log-file #$(mpd-file-name config "log"))
+ #~(make-forkexec-constructor
+ (list #$(file-append mpd "/bin/mpd")
+ "--no-daemon"
+ #$(mpd-config->file config))
+ #:environment-variables
+ ;; Required to detect PulseAudio when run under a user account.
+ (list (string-append
+ "XDG_RUNTIME_DIR=/run/user/"
+ (number->string
+ (passwd:uid
+ (getpwnam #$(mpd-configuration-user config))))))
+ #:log-file #$(mpd-file-name config "log"))))
+ (stop (if (mpd-configuration-shepherd-endpoints config)
+ #~(make-systemd-destructor)
+ #~(make-kill-destructor)))))
(define (mpd-service-activation config)
(with-imported-modules '((guix build utils))
--
2.37.3
next prev parent reply other threads:[~2022-09-10 18:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-17 10:01 [bug#54986] [PATCH] gnu: mpd: Add support for socket activation Liliana Marie Prikler
2022-04-17 10:01 ` [bug#54986] [PATCH v2 1/3] " Liliana Marie Prikler
2022-04-17 21:06 ` [bug#54986] [PATCH] " Ludovic Courtès
2022-04-17 21:57 ` Liliana Marie Prikler
2022-04-18 21:05 ` Ludovic Courtès
2022-04-18 21:19 ` Liliana Marie Prikler
2022-04-27 20:56 ` Ludovic Courtès
2022-04-28 16:45 ` Liliana Marie Prikler
2022-04-23 14:25 ` [bug#54986] [PATCH v3 1/2] services: shepherd: Add support for socket activation endpoints Liliana Marie Prikler
2023-04-26 0:33 ` [bug#54986] [PATCH] gnu: mpd: Add support for socket activation Maxim Cournoyer
2023-04-26 4:28 ` Liliana Marie Prikler
2023-05-01 15:53 ` Maxim Cournoyer
2023-05-01 16:09 ` Liliana Marie Prikler
2023-05-03 3:17 ` Maxim Cournoyer
2023-05-03 13:27 ` Ludovic Courtès
2023-05-03 16:54 ` Liliana Marie Prikler
2023-05-10 15:14 ` Ludovic Courtès
2023-05-10 18:32 ` Liliana Marie Prikler
2023-05-11 10:52 ` Ludovic Courtès
2022-04-23 14:25 ` [bug#54986] [PATCH v2 2/3 WIP] services: shepherd: Add support for socket activation endpoints Liliana Marie Prikler
2022-04-27 22:05 ` Ludovic Courtès
2022-04-23 14:39 ` Liliana Marie Prikler [this message]
2022-10-23 11:38 ` [bug#54986] [PATCH v3 2/2] services: mpd: Support socket activation Liliana Marie Prikler
2022-11-26 12:59 ` Liliana Marie Prikler
2022-04-23 14:39 ` [bug#54986] [PATCH v2 3/3 WIP] " Liliana Marie Prikler
2022-04-23 17:31 ` Maxime Devos
2022-04-23 18:36 ` Liliana Marie Prikler
2022-04-23 17:35 ` Maxime Devos
2022-04-23 18:28 ` Liliana Marie Prikler
2022-04-27 22:08 ` Ludovic Courtès
2022-05-13 15:55 ` [bug#54986] [PATCH] gnu: mpd: Add support for " Ludovic Courtès
2022-05-13 17:00 ` Liliana Marie Prikler
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
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3105812906c619735df4a5f476c1c822c63bfb15.camel@gmail.com \
--to=liliana.prikler@gmail.com \
--cc=54986@debbugs.gnu.org \
--cc=ludo@gnu.org \
--cc=maximedevos@telenet.be \
/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 public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).