From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 0K8FOaNLVWRwZwAASxT56A (envelope-from ) for ; Fri, 05 May 2023 20:32:04 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 0Ny/OKNLVWSREgEAauVa8A (envelope-from ) for ; Fri, 05 May 2023 20:32:03 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id ADF351219B for ; Fri, 5 May 2023 20:32:03 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pv0C1-0005Dk-4W; Fri, 05 May 2023 14:30:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pv0Bx-0005Ba-Mg for bug-guix@gnu.org; Fri, 05 May 2023 14:30:07 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pv0Bx-00061r-9t for bug-guix@gnu.org; Fri, 05 May 2023 14:30:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pv0Bx-0003B5-6Q for bug-guix@gnu.org; Fri, 05 May 2023 14:30:05 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#63082: [PATCH v3 07/16] services: mpd; Refactor start slot directory initialization. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Fri, 05 May 2023 18:30:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63082 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 63082@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 63082-submit@debbugs.gnu.org id=B63082.168331138411998 (code B ref 63082); Fri, 05 May 2023 18:30:05 +0000 Received: (at 63082) by debbugs.gnu.org; 5 May 2023 18:29:44 +0000 Received: from localhost ([127.0.0.1]:57487 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pv0Bb-00037R-It for submit@debbugs.gnu.org; Fri, 05 May 2023 14:29:44 -0400 Received: from mail-qk1-f180.google.com ([209.85.222.180]:54608) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pv0BX-000361-IZ for 63082@debbugs.gnu.org; Fri, 05 May 2023 14:29:40 -0400 Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7516ac80c6cso174195485a.1 for <63082@debbugs.gnu.org>; Fri, 05 May 2023 11:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683311374; x=1685903374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FzkFOQ95JVWNZbu2arG+dwpzWOEStFiVEZ/u1Hr8YAI=; b=LuSsBvExb6Qvv41VshYKK82F90RGKndvWgkGZK51v0ZgqsZvQDiwNhNtFuZ/OWWWdU dJgwfdkvE2XzMvrrZuGJw3hWFork10NJDpbrWYewch1YqJwV0UWz1kxTBnN+yQSqQYgY DcYYBOvlYRzmQ4crCLe03cNDwN6MTxox+U2gWU0YqeTNSVSLm+JMriNDbPVPD/MHrmzJ Du6loNUd0QbFtdmlFkZT/SAk8dLMHAg4p3m6ghHWubgf3heCYfLfgE1MbRne6+iOi50L OMVeHEcT8iN5whKWUNIhXsllUij/pY8SMluIjEqxBmSEmB4aifphLQB/d8RdtzRfYIk8 xTow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683311374; x=1685903374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzkFOQ95JVWNZbu2arG+dwpzWOEStFiVEZ/u1Hr8YAI=; b=ULgaz4mIgBZJPNEo5OyWexdVmpKjgvWhMAN9Bupb+dg8/9huB3Tmylszh0UWfcjMOx PRRkj+N7Wmfkjfl/RwWVuQ1lIzz2IVRbzMG+VyUfKxpy826y/huFX1xXNxmNQtjapMDo /okBbzwTSrxRXye68WYc3C+nLQLbMKgeTyQ8r17pRJ7Ok1nhpcJuQ7wgyc3nOiq8746F CJTF9OtUdzjvSYdI85VCH1DtcP2qO208+UYu6HQa9J7OzQJB3CohZJ3MrSTLx+qvgKgk AVnRjYVLbfvcb7oku1T7jP28vdVJrtygSwdOVBrQjaMMLFV6nh/Q8QauLquwF867yca3 JHkQ== X-Gm-Message-State: AC+VfDxNBA6PyNPOv0DsnzR2/1r2dzu2H1t/qnCCmso6chhtHu/ZG2kM sxWrjY6kcRejVJVbfqqqVRtdeMVZM4c= X-Google-Smtp-Source: ACHHUZ4/uwNBSR4nSHpDvEB+a+Q4c2tYtayEqJJ3qQV/wjLsMX99eercspkQ0MU4ZejAJatEIDkYaw== X-Received: by 2002:ac8:5745:0:b0:3f0:a755:61ef with SMTP id 5-20020ac85745000000b003f0a75561efmr4162232qtx.0.1683311373914; Fri, 05 May 2023 11:29:33 -0700 (PDT) Received: from localhost.localdomain (dsl-205-236-230-162.b2b2c.ca. [205.236.230.162]) by smtp.gmail.com with ESMTPSA id c1-20020ac81e81000000b003e97fe68511sm834399qtm.3.2023.05.05.11.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 11:29:33 -0700 (PDT) From: Maxim Cournoyer Date: Fri, 5 May 2023 14:29:02 -0400 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1683311523; a=rsa-sha256; cv=none; b=i1C8Wt4eea7qNj5oYEiZR0wH9SWt55VqwDWANGJip1RLZA9zmf8E1Tv+nrihFn61IS7Jfn +tfM8iyyKIQAoenF3iheviVEM3yC2jyIm93E/YlxMkm2tm3mEXF1ld5KfvhGlZXZv6ADNz ZXBcb4c7vhoyCwZ20CFnodfpN7N7y7s1YhMMVMYIxAcBj7LVRE7QmVX2AvOym6C24zjwRj fMYH9RhMoBM5geVr3rnDGWGpjnOdyiqYsswD7rwq/lk5sviGCE+lO/BDo/YPIRBue06Wz2 +ynq7gkBJMBJZtXPILbj96Q9+XuN7SPE2PnFy16xg2r3oCC3mealUJLGFiEHWQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=LuSsBvEx; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1683311523; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=FzkFOQ95JVWNZbu2arG+dwpzWOEStFiVEZ/u1Hr8YAI=; b=o1B/klmurFGYyPj00gzylP8KmVim4VY4ZPHvRHa+gThhrdKrvjeqaEWlfazC3t3xpm8RFf dPXruKSNwtEJ35GqWmYbZsJnqE0YzUaj+xXpYsLfepsssqkvycXPXwnttL8Pe3H1pNWr4W tRSDcPHLx7QtSb33DYf7B5rDyvS237UqUw7Q9R/m1uIpr+cNFnZM3esInebJh0DWLhGDWk ldOeGhAgTMqi2oeh4PdGKAMgL4GTgmhmnY+TuwazyH0YrYI4L05r/fU1S/8mnf3HrkPQGN rRffx/ZKZ947/VwQsizxt4vSxbZfkiZnP+qhxkpIbhGa10joptXCipkYMzyWnQ== X-Migadu-Spam-Score: -2.70 X-Spam-Score: -2.70 X-Migadu-Queue-Id: ADF351219B X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=LuSsBvEx; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-TUID: Sw9en/5jstTQ * gnu/services/audio.scm (mpd-shepherd-service): Standardize the way the log file parent and other directories are initialized in the start slot. (mympd-shepherd-service): Likewise. --- gnu/services/audio.scm | 132 ++++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 55 deletions(-) diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm index ead4cb8d90..6e57bf5cba 100644 --- a/gnu/services/audio.scm +++ b/gnu/services/audio.scm @@ -24,6 +24,7 @@ (define-module (gnu services audio) #:use-module (guix deprecation) #:use-module (guix diagnostics) #:use-module (guix i18n) + #:use-module (guix modules) #:use-module (gnu services) #:use-module (gnu services admin) #:use-module (gnu services configuration) @@ -552,36 +553,45 @@ (define (mpd-log-rotation config) (with-shepherd-action 'mpd ('reopen) #f)))))) (define (mpd-shepherd-service config) - (match-record config (user package shepherd-requirement - log-file playlist-directory - db-file state-file sticker-file - environment-variables) + (match-record config + (user package shepherd-requirement + log-file playlist-directory + db-file state-file sticker-file + environment-variables) (let ((config-file (mpd-serialize-configuration config)) (username (user-account-name user))) (shepherd-service (documentation "Run the MPD (Music Player Daemon)") (requirement `(user-processes loopback ,@shepherd-requirement)) (provision '(mpd)) - (start #~(begin - (and=> #$(maybe-value log-file) - (compose mkdir-p dirname)) - - (let ((user (getpw #$username))) - (for-each - (lambda (x) - (when (and x (not (file-exists? x))) - (mkdir-p x) - (chown x (passwd:uid user) (passwd:gid user)))) - (list #$(maybe-value playlist-directory) - (and=> #$(maybe-value db-file) dirname) - (and=> #$(maybe-value state-file) dirname) - (and=> #$(maybe-value sticker-file) dirname)))) - - (make-forkexec-constructor - (list #$(file-append package "/bin/mpd") - "--no-daemon" - #$config-file) - #:environment-variables '#$environment-variables))) + (start + (with-imported-modules (source-module-closure + '((gnu build activation))) + #~(begin + (use-modules (gnu build activation)) + + (let ((user (getpw #$username))) + + (define (init-directory directory) + (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 db-file + log-file + state-file + sticker-file)))))) + + (make-forkexec-constructor + (list #$(file-append package "/bin/mpd") "--no-daemon" + #$config-file) + #:environment-variables '#$environment-variables)))) (stop #~(make-kill-destructor)) (actions (list (shepherd-configuration-action config-file) @@ -833,37 +843,49 @@ (define (mympd-serialize-configuration config) filename-to-field))))) (define (mympd-shepherd-service config) - (match-record config (package shepherd-requirement - user work-directory - cache-directory log-level log-to) - (let ((log-level* (format #f "MYMPD_LOGLEVEL=~a" log-level)) - (username (user-account-name user))) - (shepherd-service - (documentation "Run the myMPD daemon.") - (requirement `(loopback user-processes - ,@(if (eq? log-to 'syslog) - '(syslog) - '()) - ,@shepherd-requirement)) - (provision '(mympd)) - (start #~(begin - (let* ((pw (getpwnam #$username)) - (uid (passwd:uid pw)) - (gid (passwd:gid pw))) - (for-each (lambda (dir) - (mkdir-p dir) - (chown dir uid gid)) - (list #$work-directory #$cache-directory))) - - (make-forkexec-constructor - `(#$(file-append package "/bin/mympd") - "--user" #$username - #$@(if (eq? log-to 'syslog) '("--syslog") '()) - "--workdir" #$work-directory - "--cachedir" #$cache-directory) - #:environment-variables (list #$log-level*) - #:log-file #$(if (string? log-to) log-to #f)))) - (stop #~(make-kill-destructor)))))) + (match-record config + (package shepherd-requirement user work-directory cache-directory + log-level log-to) + (shepherd-service + (documentation "Run the myMPD daemon.") + (requirement `(loopback user-processes + ,@(if (eq? log-to 'syslog) + '(syslog) + '()) + ,@shepherd-requirement)) + (provision '(mympd)) + (start + (let ((username (user-account-name user))) + (with-imported-modules (source-module-closure + '((gnu build activation))) + #~(begin + (use-modules (gnu build activation)) + + (let ((user (getpw #$username))) + + (define (init-directory directory) + (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)))))) + (make-forkexec-constructor + `(#$(file-append package "/bin/mympd") + "--user" #$username + #$@(if (eq? log-to 'syslog) '("--syslog") '()) + "--workdir" #$work-directory + "--cachedir" #$cache-directory) + #:environment-variables + (list #$(format #f "MYMPD_LOGLEVEL=~a" log-level)) + #:log-file #$(if (string? log-to) log-to #f))))))))) (define (mympd-accounts config) (match-record config -- 2.39.2