From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id kOg/H314TWRlewAASxT56A (envelope-from ) for ; Sat, 29 Apr 2023 22:05:17 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id KGRKH314TWQ4qwAAauVa8A (envelope-from ) for ; Sat, 29 Apr 2023 22:05:17 +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 EAC503A7C for ; Sat, 29 Apr 2023 22:05:16 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psoHq-00014r-JH; Sat, 29 Apr 2023 13:23:06 -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 1psoHp-000145-H2 for bug-guix@gnu.org; Sat, 29 Apr 2023 13:23:05 -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 1psoHp-0003My-8c for bug-guix@gnu.org; Sat, 29 Apr 2023 13:23:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1psoHp-00007n-1m for bug-guix@gnu.org; Sat, 29 Apr 2023 13:23:05 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#63082: [PATCH v2 06/16] services: mpd; Refactor start slot directory initialization. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sat, 29 Apr 2023 17:23: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.168278894032721 (code B ref 63082); Sat, 29 Apr 2023 17:23:05 +0000 Received: (at 63082) by debbugs.gnu.org; 29 Apr 2023 17:22:20 +0000 Received: from localhost ([127.0.0.1]:36562 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psoH6-0008Vb-5w for submit@debbugs.gnu.org; Sat, 29 Apr 2023 13:22:20 -0400 Received: from mail-qv1-f50.google.com ([209.85.219.50]:47413) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psoGz-0008Tp-Tf for 63082@debbugs.gnu.org; Sat, 29 Apr 2023 13:22:14 -0400 Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6196146d636so1444306d6.3 for <63082@debbugs.gnu.org>; Sat, 29 Apr 2023 10:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682788928; x=1685380928; 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=bK5/xnTlBkGscbomDqvm4YGAof9c1FcI3qsLL0kUYZIYrDTphZFOrRxhgTSI1xpBE+ Vm8TonWt+CjY7Kp1uXw5lZO8ZNfGeQYBhT0nE71gnObw34GnhtDk9I8ZNj/e9OZN7b5e dFpbkrie2koPG9htiiJytnU9B0vUR7R2A2F1KA4gUPbI9MkoIT7p5dFVZ/0JtC73mkhh F0ST6XdBBNhirQhD7IUk0+/g10FS1sQfdG44etX0DYG+Er0QYs2FzbGpbCHDcVbKioWK D3jkWpLSgqAqPK/gOHaDp/AX5rnYhSylM3eJ2vCiZYVF6BYqnL7TtrjoTXLnGjcmEcTb DnDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682788928; x=1685380928; 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=PNMvfuPrv81UGDQejgdzqagbAwLNIAfU4KVL7ed7y61XYnLqeEf4WmD7x/sbbKcP0i g77UKbho2zbDZbxMpUr8ZBSFbxv3pYW2NErmh+B6WHU2HQ3U6D1x2aMHCCPPevfCuhno u0qTXaW61At5SKzDYTEbYoy6FrnBrnZ2Hu0yyTFQ6PiqjO6WBxUEfXzRwAt975lg9hIu UEw2Vf7Q60n7WgUVP1ifZ8+ZqKKRZC+/9LMJDQOMEv/hz2xk5hQYKN25C3lrFgVndE9j +Idkw5k/dcGlyt6owmoIKdZO3eICh+vi4FomoWp1DhMw7qWyC9pYmB8yVIgmn3geBoGw OuUQ== X-Gm-Message-State: AC+VfDwAtM78zV8QnbzvPkvoAuiOi/ycWDUkaZQlTUC94pGNtzgau5c+ Ln9lABUJxJyhhelvnQb0TLJnXJKWdYI= X-Google-Smtp-Source: ACHHUZ5U6meC8ylLP/rFPgEnm9x9A9D6atCU4lHfJt+zW9l3DSK+NA1392IaznQr1X6yzNleDh5v7A== X-Received: by 2002:a05:6214:627:b0:5af:af15:8d44 with SMTP id a7-20020a056214062700b005afaf158d44mr13793315qvx.45.1682788928165; Sat, 29 Apr 2023 10:22:08 -0700 (PDT) Received: from localhost.localdomain (dsl-155-245.b2b2c.ca. [66.158.155.245]) by smtp.gmail.com with ESMTPSA id dm45-20020a05620a1d6d00b0074cf009f443sm7582489qkb.85.2023.04.29.10.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 10:22:07 -0700 (PDT) From: Maxim Cournoyer Date: Sat, 29 Apr 2023 13:21:43 -0400 Message-Id: <05631cf44341b93ef5b91337e21f9d49f3b3b824.1682788743.git.maxim.cournoyer@gmail.com> 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=1682798717; a=rsa-sha256; cv=none; b=G1zqJ5Tr6GBsepCDbnPqKyrnDzupuu1NgNUQ2Kv1cgaswiNJLKuKkRdrXiLuXvWAsKaTgO KPnAUxVow+10+yDJN5DgGD+o/MEglF2/8aW3FAitJRYtyI9zrVQ8wWPZTWxOb3OEismtIS qgZI2Q4FxxVDFyUNXeq0XJ2nYr+chKtmnTrh9Tspb5V8x8eINMDLPxLOWCf69WidlNukhF E+cqYtwXON6/8wfPuBkf0/1Setrtt5AQQUIpVKMjKsVHq+j0A0atSY8jhZpfQX552fvxpH RhoTnjUILZWgg4yExuvoFArNbKpxeq0vEGOAnAuqbBa+zGUHcqxiEYcgmOQdBA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b="bK5/xnTl"; 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=1682798717; 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=T1DLW6gVcR464yFceGAnbdkMvIu1ltfwRIDx6IaroTwh+B/sg0poIkroqRoBWAi+EdJdLQ zOEFBuM9aXISzrBTz1QPsSVWDwEpvIZH5WSKPDzQlI+5qsovYgvEFxRWx3mT/gD5i2JLyT Vh74Hlgt8Fofoa5ZttD+4g3Js0M3YHZDO2v3h9ZIFd/VnI3o1lMsr6jrDauEUMZODNj+kV YH51eshlHSl/wHosSPqBCKedrv/FUaJN8/bRezhEBhBllI+umzYGOHlEE12IbVxKEjvhYM 8n0sPx0G9olN9uFuL7q/fGwEwp5qbhJkCIgBQx0yh7kvdags3ETGLQR8B2elqQ== X-Migadu-Spam-Score: -0.90 X-Spam-Score: -0.90 X-Migadu-Queue-Id: EAC503A7C 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="bK5/xnTl"; 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: Lh7Lex8lJ6Rv * 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