Message ID | 2e5292c2d45e525aa1b8e4c495704104d4121291.camel@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org> X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id CF23227BBEA; Sat, 23 Apr 2022 14:23:58 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 994F127BBE9 for <patchwork@mira.cbaines.net>; Sat, 23 Apr 2022 14:23:58 +0100 (BST) Received: from localhost ([::1]:56854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org>) id 1niFjx-0005qE-QB for patchwork@mira.cbaines.net; Sat, 23 Apr 2022 09:23:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1niFeE-0005oN-NT for guix-patches@gnu.org; Sat, 23 Apr 2022 09:18:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1niFeE-0000h1-Cz for guix-patches@gnu.org; Sat, 23 Apr 2022 09:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1niFeE-0006O5-9H for guix-patches@gnu.org; Sat, 23 Apr 2022 09:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55080] [PATCH shepherd] service: Gracefully handle non-existing log directories. Resent-From: Liliana Marie Prikler <liliana.prikler@gmail.com> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 23 Apr 2022 13:18:02 +0000 Resent-Message-ID: <handler.55080.B.165071985324217@debbugs.gnu.org> Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55080 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55080@debbugs.gnu.org Cc: ludo@gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.165071985324217 (code B ref -1); Sat, 23 Apr 2022 13:18:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Apr 2022 13:17:33 +0000 Received: from localhost ([127.0.0.1]:55462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1niFdk-0006IO-KP for submit@debbugs.gnu.org; Sat, 23 Apr 2022 09:17:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:53812) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <liliana.prikler@gmail.com>) id 1niFdi-0006HN-Rx for submit@debbugs.gnu.org; Sat, 23 Apr 2022 09:17:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <liliana.prikler@gmail.com>) id 1niFdi-0004z1-7x for guix-patches@gnu.org; Sat, 23 Apr 2022 09:17:30 -0400 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]:33336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <liliana.prikler@gmail.com>) id 1niFdg-0000ea-Bz; Sat, 23 Apr 2022 09:17:29 -0400 Received: by mail-ed1-x542.google.com with SMTP id e30so9964941eda.0; Sat, 23 Apr 2022 06:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:subject:to:cc:content-transfer-encoding:message-id :mime-version; bh=LzLJ6HhTZdQMiXZb0LVHUWGq6v6jGE0mOLNURaveW/c=; b=lkcyrcoAZJzIL2LnHAPLzqjnA5jgon2YgEy520ma128SXTs5rMqLrhws30cTOKltv0 EEueM0KcmFdtvQev+KZsGctRpepgetkcOqOHYK/kl8UxUIgdgnl5Ud7+lzkkU7FLL9GK G09HJrNSApWgy+amy1ltJ2AkZ5aM0r8vyazWDUoV/3knwVGB/Cb03jyXGs6EHuAtIRon cZzNtv1uspuDXXAbqBvp9I3hsVagTghaYmI4VGeCawUCetbaWcaU8y4K0P2vdhKGH8eA 2+coEAJBTZmccLeL2Nozod9OU5rY0YsVXVCFUllq2jcnhtwXlbCvAtsBBzU2H3rMO4Gk QxxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:subject:to:cc :content-transfer-encoding:message-id:mime-version; bh=LzLJ6HhTZdQMiXZb0LVHUWGq6v6jGE0mOLNURaveW/c=; b=J/xY9UVLX0DqZ9spplF31hEdegUqyB306Snr+Cq2h2CbAk3RcTmuF9UwK5Cgj/y8r6 sv4iieuos95sHNdtXHVSZMo4pM1GOgRPkpBibuAi60JBivaDOZUYLFy3DV41oRCQW1Tc ee8nmbv/Fk9/m9jmJUQOC3jgnTXx0TqHctGRCZZ1dtbCNMy4/RvjtDou8FRSpGUwyZfF cVFXW9hm/fPX/ezJrv4gK1SrISLr7HpvJENOieGbkcrGUNm9aKFqKlSsdlDXXv4TifC8 0iiZ5c0+BOwWGH0Ttc3cMhrK1cqQMcZppHXC3xClkibIwfmkm+Q3peeg7gTJrbHbxw3/ B+aw== X-Gm-Message-State: AOAM530S97TqeyibpBtiArv7Vw4OdWPnnS/MtnDp280UgClE86lIfEpI 1/wGsU6p9I9eOdhi8PUHZc5yM4PmyEE= X-Google-Smtp-Source: ABdhPJxcOEDoCWbau2L6N86ZiUSRcMdsQj19YI430iE10gDj59WANsnEl8MEJhKseh0dixheUY5ZKQ== X-Received: by 2002:a05:6402:b57:b0:41d:6d9b:7e0d with SMTP id bx23-20020a0564020b5700b0041d6d9b7e0dmr10020860edb.78.1650719844739; Sat, 23 Apr 2022 06:17:24 -0700 (PDT) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id h22-20020a056402281600b004206bd9d0c6sm2287355ede.8.2022.04.23.06.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 06:17:24 -0700 (PDT) From: Liliana Marie Prikler <liliana.prikler@gmail.com> Date: Sat, 23 Apr 2022 15:11:50 +0200 Content-Transfer-Encoding: 7bit Message-ID: <2e5292c2d45e525aa1b8e4c495704104d4121291.camel@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::542; envelope-from=liliana.prikler@gmail.com; helo=mail-ed1-x542.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: <guix-patches.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/guix-patches>, <mailto:guix-patches-request@gnu.org?subject=unsubscribe> List-Archive: <https://lists.gnu.org/archive/html/guix-patches> List-Post: <mailto:guix-patches@gnu.org> List-Help: <mailto:guix-patches-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/guix-patches>, <mailto:guix-patches-request@gnu.org?subject=subscribe> Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" <guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org> X-getmail-retrieved-from-mailbox: Patches |
Series |
[bug#55080,shepherd] service: Gracefully handle non-existing log directories.
|
|
Commit Message
Liliana Marie Prikler
April 23, 2022, 1:11 p.m. UTC
* gnu/packages/services.scm (%service-file-logger): New variable, implementing... (service-file-logger): ... the old behaviour of this variable. Catch system errors from %service-file-logger and handle them. --- modules/shepherd/service.scm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
Comments
Hi, Liliana Marie Prikler <liliana.prikler@gmail.com> skribis: > * gnu/packages/services.scm (%service-file-logger): New variable, > implementing... > (service-file-logger): ... the old behaviour of this variable. Catch system > errors from %service-file-logger and handle them. [...] > +(define (service-file-logger file input) > + "Return a thunk meant to run as a fiber that reads from INPUT and logs it to > +FILE." > + (catch 'system-error > + (lambda () > + (%service-file-logger file input)) > + (lambda args > + (if (= ENOENT (system-error-errno args)) > + (begin > + (mkdir-p (dirname file)) > + (%service-file-logger file input)) > + (apply throw args))))) I wonder to what extent automatically creating log directories is a good idea. A potential drawback is if shepherd creates them with unexpected ownership or permissions. Did you encounter this issue while working on services? Am I right that the Shepherd 0.8 had the same problem? Thanks, Ludo’.
Am Samstag, dem 30.04.2022 um 16:15 +0200 schrieb Ludovic Courtès: > > > +(define (service-file-logger file input) > > + "Return a thunk meant to run as a fiber that reads from INPUT > > and logs it to > > +FILE." > > + (catch 'system-error > > + (lambda () > > + (%service-file-logger file input)) > > + (lambda args > > + (if (= ENOENT (system-error-errno args)) > > + (begin > > + (mkdir-p (dirname file)) > > + (%service-file-logger file input)) > > + (apply throw args))))) > > I wonder to what extent automatically creating log directories is a > good idea. A potential drawback is if shepherd creates them with > unexpected ownership or permissions. As far as I know, those logs should be managed by shepherd, no? It just redirects stdout/stderr there, or is there something special going on? > Did you encounter this issue while working on services? > > Am I right that the Shepherd 0.8 had the same problem? It might be, I don't know. I've encountered this for non-existing log directory, so a reproducer would be setting #:log-file to $test-tmp- directory/does-not-exist/log and check for each service. Cheers
Liliana Marie Prikler <liliana.prikler@gmail.com> skribis: > Am Samstag, dem 30.04.2022 um 16:15 +0200 schrieb Ludovic Courtès: [...] >> Did you encounter this issue while working on services? >> >> Am I right that the Shepherd 0.8 had the same problem? > It might be, I don't know. I've encountered this for non-existing log > directory, so a reproducer would be setting #:log-file to $test-tmp- > directory/does-not-exist/log and check for each service. Usually /var/log and similar directories are created not by shepherd but by Guix System, the distro being used, or whatever. That’s why I wonder if it’s shepherd’s job to do that. I was asking how you encountered it to better understand in which circumstances the problem can occur in practice and what the failure more is like. Thanks, Ludo’.
Am Sonntag, dem 01.05.2022 um 15:32 +0200 schrieb Ludovic Courtès: > > > > > Did you encounter this issue while working on services? > > > > > > Am I right that the Shepherd 0.8 had the same problem? > > It might be, I don't know. I've encountered this for non-existing > > log directory, so a reproducer would be setting #:log-file to > > $test-tmp-directory/does-not-exist/log and check for each service. > > Usually /var/log and similar directories are created not by shepherd > but by Guix System, the distro being used, or whatever. That’s why I > wonder if it’s shepherd’s job to do that. Hmm, it might not be. Still, I wouldn't like shepherd to fail in such a weird manner if the log file can't be created. Should we write a warning to shepherd's log and redirect to /dev/null instead? Should we just kill the service?
Hi Liliana, Liliana Marie Prikler <liliana.prikler@gmail.com> skribis: > Am Sonntag, dem 01.05.2022 um 15:32 +0200 schrieb Ludovic Courtès: >> > >> > > Did you encounter this issue while working on services? >> > > >> > > Am I right that the Shepherd 0.8 had the same problem? >> > It might be, I don't know. I've encountered this for non-existing >> > log directory, so a reproducer would be setting #:log-file to >> > $test-tmp-directory/does-not-exist/log and check for each service. >> >> Usually /var/log and similar directories are created not by shepherd >> but by Guix System, the distro being used, or whatever. That’s why I >> wonder if it’s shepherd’s job to do that. > Hmm, it might not be. Still, I wouldn't like shepherd to fail in such > a weird manner if the log file can't be created. I reread this thread and I concur. Patch finally pushed as b0d3f625543bcb32e94167c27cba153f9fc03acd. Thanks, Ludo’.
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index 013347b..567a08b 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -873,9 +873,9 @@ daemon writing FILE is running in a separate PID namespace." (try-again) (apply throw args))))))) -(define (service-file-logger file input) - "Return a thunk meant to run as a fiber that reads from INPUT and logs it to -FILE." +(define (%service-file-logger file input) + "Like 'service-file-logger', but doesn't handle the case in which FILE does +not exist." (let* ((fd (open-fdes file (logior O_CREAT O_WRONLY O_APPEND) #o640)) (output (fdopen fd "al"))) (set-port-encoding! output "UTF-8") @@ -894,6 +894,19 @@ FILE." (format output "~a~a~%" prefix line) (loop)))))))))) +(define (service-file-logger file input) + "Return a thunk meant to run as a fiber that reads from INPUT and logs it to +FILE." + (catch 'system-error + (lambda () + (%service-file-logger file input)) + (lambda args + (if (= ENOENT (system-error-errno args)) + (begin + (mkdir-p (dirname file)) + (%service-file-logger file input)) + (apply throw args))))) + (define (service-builtin-logger command input) "Return a thunk meant to run as a fiber that reads from INPUT and logs to 'log-output-port'."