1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-04-06 21:20:33 +02:00

services: readymedia: Run with a pid file.

* gnu/services/upnp.scm (%readymedia-default-pid-directory): New variable.
(%readymedia-pid-file): New procedure.
(readymedia-shepherd-service)[start]: Start with the pid file.
(readymedia-activation): Create the pid directory.
* gnu/tests/upnp.scm (run-readymedia-test): Test the pid directory and file.

Merges: https://codeberg.org/guix/guix/pulls/1007
Change-Id: I454a89d25afe0e9bb0414645b1e4594afdf89058
Signed-off-by: Giacomo Leidi <therewasa@fishinthecalculator.me>
This commit is contained in:
Sughosha
2026-02-20 00:36:49 +05:30
committed by Giacomo Leidi
parent f19ddd6dfe
commit 4b8cfa7f69
2 changed files with 55 additions and 11 deletions

View File

@@ -33,6 +33,8 @@
#:use-module (ice-9 match)
#:export (%readymedia-default-cache-directory
%readymedia-default-log-file
%readymedia-default-pid-directory
%readymedia-pid-file
%readymedia-user-account
%readymedia-user-group
readymedia-configuration
@@ -68,6 +70,13 @@
(use-modules (shepherd support)) ;for %user-log-dir
(string-append %user-log-dir "/readymedia.log"))
"/var/log/readymedia.log"))
(define %readymedia-default-pid-directory "/var/run/readymedia")
(define* (%readymedia-pid-file #:key (home-service? #f) (name "minidlna.pid"))
(if home-service?
#~(begin
(use-modules (shepherd support)) ;for %user-runtime-dir
(string-append %user-runtime-dir "/readymedia/" #$name))
(string-append %readymedia-default-pid-directory "/" name)))
(define %readymedia-user-group "readymedia")
(define %readymedia-user-account "readymedia")
@@ -156,6 +165,10 @@
(source cache-directory)
(target source)
(writable? #t))
(file-system-mapping
(source %readymedia-default-pid-directory)
(target source)
(writable? #t))
(file-system-mapping
(source minidlna-conf)
(target source))
@@ -168,6 +181,8 @@
#:namespaces (delq 'net %namespaces))
"-f"
#$minidlna-conf
"-P"
#$(%readymedia-pid-file)
"-S")
#:log-file #$log-file
#:user #$(if home-service? #f %readymedia-user-account)
@@ -182,6 +197,8 @@
"/sbin/minidlnad")
"-f"
#$minidlna-conf
"-P"
#$(%readymedia-pid-file #:home-service? home-service?)
"-S")
#:log-file #$log-file)))
(stop #~(make-kill-destructor))))))
@@ -215,17 +232,23 @@
#$(if home-service? #o755 #o775))))
(list #$@(map readymedia-media-directory-path
media-directories)))
(unless (file-exists? directory)
(mkdir-p/perms (if (absolute-file-name? #$cache-directory)
#$cache-directory
(string-append (or (getenv "HOME")
(passwd:dir
(getpwuid (getuid))))
"/" #$cache-directory))
(getpw #$(if home-service?
#~(getuid)
%readymedia-user-account))
#o755))))))
(for-each (lambda (directory)
(unless (file-exists? directory)
(mkdir-p/perms directory
(getpw #$(if home-service?
#~(getuid)
%readymedia-user-account))
#o755)))
(list (if #$home-service?
(if (absolute-file-name? #$cache-directory)
#$cache-directory
(string-append (or (getenv "HOME")
(passwd:dir
(getpwuid (getuid))))
"/" #$cache-directory))
#$cache-directory)
(dirname #$(%readymedia-pid-file
#:home-service? home-service?))))))))
(define readymedia-service-type
(service-type

View File

@@ -99,6 +99,27 @@
'(file-exists? #$(%readymedia-default-log-file))
marionette))
;; Pid directory and file
(test-assert "pid directory exists"
(marionette-eval
'(eq? (stat:type (stat #$%readymedia-default-pid-directory))
'directory)
marionette))
(test-assert "pid directory has correct ownership"
(marionette-eval
'(let ((pid-dir (stat #$%readymedia-default-pid-directory))
(user (getpwnam #$%readymedia-user-account)))
(and (eqv? (stat:uid pid-dir) (passwd:uid user))
(eqv? (stat:gid pid-dir) (passwd:gid user))))
marionette))
(test-assert "pid directory has expected permissions"
(marionette-eval
'(eqv? (stat:perms (stat #$%readymedia-default-pid-directory))
#o755)
marionette))
(test-assert "containerd PID file present"
(wait-for-file #$(%readymedia-pid-file) marionette))
;; Service
(test-assert "ReadyMedia service is running"
(marionette-eval