Skip to content
Snippets Groups Projects
Unverified Commit b6dc69af authored by Peter Mikkelsen's avatar Peter Mikkelsen Committed by Ludovic Courtès
Browse files

services: mpd: Remove the mpd-file field.


Since MPD switches user, the pid-file must be in a writable dir.  This
is now always /var/run/mpd/(user)/pid.

* gnu/services/audio.scm (mpd-service-type): Add a activation-service
extension.
(<mpd-configuration>)[pid-file]: Remove.
(mpd-service): Rename to...
(mpd-shepherd-service): ... this.
(mpd-file-name, mpd-service-activation): New procedure.
* doc/guix.texi (Audio Services): Document the changes.

Signed-off-by: default avatarLudovic Courtès <ludo@gnu.org>
parent 79ada57b
No related branches found
No related tags found
No related merge requests found
...@@ -15844,9 +15844,6 @@ The directory to scan for music files. ...@@ -15844,9 +15844,6 @@ The directory to scan for music files.
@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) @item @code{playlist-dir} (default: @code{"~/.mpd/playlists"})
The directory to store playlists. The directory to store playlists.
   
@item @code{pid-file} (default: @code{"/var/run/mpd.pid"})
The file mpd wil store its PID. This must be an absolute path.
@item @code{port} (default: @code{"6600"}) @item @code{port} (default: @code{"6600"})
The port to run mpd on. The port to run mpd on.
   
......
...@@ -45,9 +45,7 @@ (define-record-type* <mpd-configuration> ...@@ -45,9 +45,7 @@ (define-record-type* <mpd-configuration>
(port mpd-configuration-port (port mpd-configuration-port
(default "6600")) (default "6600"))
(address mpd-configuration-address (address mpd-configuration-address
(default "any")) (default "any")))
(pid-file mpd-configuration-pid-file
(default "/var/run/mpd.pid")))
(define (mpd-config->file config) (define (mpd-config->file config)
(apply (apply
...@@ -56,6 +54,7 @@ (define (mpd-config->file config) ...@@ -56,6 +54,7 @@ (define (mpd-config->file config)
" type \"pulse\"\n" " type \"pulse\"\n"
" name \"MPD\"\n" " name \"MPD\"\n"
"}\n" "}\n"
"pid_file \"" (mpd-file-name config "pid") "\"\n"
(map (match-lambda (map (match-lambda
((config-name config-val) ((config-name config-val)
(string-append config-name " \"" (config-val config) "\"\n"))) (string-append config-name " \"" (config-val config) "\"\n")))
...@@ -63,10 +62,16 @@ (define (mpd-config->file config) ...@@ -63,10 +62,16 @@ (define (mpd-config->file config)
("music_directory" ,mpd-configuration-music-dir) ("music_directory" ,mpd-configuration-music-dir)
("playlist_directory" ,mpd-configuration-playlist-dir) ("playlist_directory" ,mpd-configuration-playlist-dir)
("port" ,mpd-configuration-port) ("port" ,mpd-configuration-port)
("bind_to_address" ,mpd-configuration-address) ("bind_to_address" ,mpd-configuration-address)))))
("pid_file" ,mpd-configuration-pid-file)))))
(define (mpd-service config) (define (mpd-file-name config file)
"Return a path in /var/run/mpd/ that is writable
by @code{user} from @code{config}."
(string-append "/var/run/mpd/"
(mpd-configuration-user config)
"/" file))
(define (mpd-shepherd-service config)
(shepherd-service (shepherd-service
(documentation "Run the MPD (Music Player Daemon)") (documentation "Run the MPD (Music Player Daemon)")
(provision '(mpd)) (provision '(mpd))
...@@ -74,13 +79,27 @@ (define (mpd-service config) ...@@ -74,13 +79,27 @@ (define (mpd-service config)
(list #$(file-append mpd "/bin/mpd") (list #$(file-append mpd "/bin/mpd")
"--no-daemon" "--no-daemon"
#$(mpd-config->file config)) #$(mpd-config->file config))
#:pid-file #$(mpd-configuration-pid-file config))) #:pid-file #$(mpd-file-name config "pid")
#:log-file #$(mpd-file-name config "log")))
(stop #~(make-kill-destructor)))) (stop #~(make-kill-destructor))))
(define (mpd-service-activation config)
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
(define %user
(getpw #$(mpd-configuration-user config)))
(let ((directory #$(mpd-file-name config "")))
(mkdir-p directory)
(chown directory (passwd:uid %user) (passwd:gid %user))))))
(define mpd-service-type (define mpd-service-type
(service-type (service-type
(name 'mpd) (name 'mpd)
(extensions (extensions
(list (service-extension shepherd-root-service-type (list (service-extension shepherd-root-service-type
(compose list mpd-service)))) (compose list mpd-shepherd-service))
(service-extension activation-service-type
mpd-service-activation)))
(default-value (mpd-configuration)))) (default-value (mpd-configuration))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment