GNU bug report logs - #36451
[PATCH] gnu: services: postgresql: Don't initdb when directory exists

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: Robert Vollmert <rob@HIDDEN>; Keywords: patch; dated Sun, 30 Jun 2019 20:57:03 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 30 Jun 2019 20:56:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 30 16:56:56 2019
Received: from localhost ([127.0.0.1]:47361 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1hhgsa-0006Fh-4R
	for submit <at> debbugs.gnu.org; Sun, 30 Jun 2019 16:56:56 -0400
Received: from lists.gnu.org ([209.51.188.17]:54105)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <rob@HIDDEN>) id 1hhgsY-0006FV-Hd
 for submit <at> debbugs.gnu.org; Sun, 30 Jun 2019 16:56:54 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:37988)
 by lists.gnu.org with esmtp (Exim 4.86_2)
 (envelope-from <rob@HIDDEN>) id 1hhgsW-0002gu-Pw
 for guix-patches@HIDDEN; Sun, 30 Jun 2019 16:56:54 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_LOW
 autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <rob@HIDDEN>) id 1hhgsU-0001ky-0D
 for guix-patches@HIDDEN; Sun, 30 Jun 2019 16:56:51 -0400
Received: from mx1.mailbox.org ([80.241.60.212]:34076)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <rob@HIDDEN>) id 1hhgsT-0001gs-Bx
 for guix-patches@HIDDEN; Sun, 30 Jun 2019 16:56:49 -0400
Received: from smtp2.mailbox.org (smtp2.mailbox.org
 [IPv6:2001:67c:2050:105:465:1:2:0])
 (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits))
 (No client certificate requested)
 by mx1.mailbox.org (Postfix) with ESMTPS id A92745034E;
 Sun, 30 Jun 2019 22:56:46 +0200 (CEST)
X-Virus-Scanned: amavisd-new at heinlein-support.de
Received: from smtp2.mailbox.org ([80.241.60.241])
 by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de
 [80.241.56.116]) (amavisd-new, port 10030)
 with ESMTP id ObQnP6pi6EQw; Sun, 30 Jun 2019 22:56:45 +0200 (CEST)
From: Robert Vollmert <rob@HIDDEN>
To: guix-patches@HIDDEN
Subject: [PATCH] gnu: services: postgresql: Don't initdb when directory exists
Date: Sun, 30 Jun 2019 22:56:42 +0200
Message-Id: <20190630205642.54866-1-rob@HIDDEN>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 80.241.60.212
X-Spam-Score: -1.6 (-)
X-Debbugs-Envelope-To: submit
Cc: Robert Vollmert <rob@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.6 (--)

* gnu/services/databases.scm (postgresql-activation): Check if
directory exists.
---
 gnu/services/databases.scm | 63 +++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 31 deletions(-)

diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index ec31489d48..6b04ae0a0f 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -196,37 +196,38 @@ host	all	all	::1/128 	md5"))
          (use-modules (guix build utils)
                       (ice-9 match))
=20
-         (let ((user (getpwnam "postgres"))
-               (initdb (string-append #$(final-postgresql postgresql ext=
ension-packages)
-                                      "/bin/initdb"))
-               (initdb-args
-                (append
-                 (if #$locale
-                     (list (string-append "--locale=3D" #$locale))
-                     '()))))
-           ;; Create db state directory.
-           (mkdir-p #$data-directory)
-           (chown #$data-directory (passwd:uid user) (passwd:gid user))
-
-           ;; Drop privileges and init state directory in a new
-           ;; process.  Wait for it to finish before proceeding.
-           (match (primitive-fork)
-             (0
-              ;; Exit with a non-zero status code if an exception is thr=
own.
-              (dynamic-wind
-                (const #t)
-                (lambda ()
-                  (setgid (passwd:gid user))
-                  (setuid (passwd:uid user))
-                  (primitive-exit
-                   (apply system*
-                          initdb
-                          "-D"
-                          #$data-directory
-                          initdb-args)))
-                (lambda ()
-                  (primitive-exit 1))))
-             (pid (waitpid pid))))))))
+         (when (not (file-exists? #$data-directory))
+           (let ((user (getpwnam "postgres"))
+                 (initdb (string-append #$(final-postgresql postgresql e=
xtension-packages)
+                                        "/bin/initdb"))
+                 (initdb-args
+                  (append
+                   (if #$locale
+                       (list (string-append "--locale=3D" #$locale))
+                       '()))))
+             ;; Create db state directory.
+             (mkdir-p #$data-directory)
+             (chown #$data-directory (passwd:uid user) (passwd:gid user)=
)
+
+             ;; Drop privileges and init state directory in a new
+             ;; process.  Wait for it to finish before proceeding.
+             (match (primitive-fork)
+               (0
+                ;; Exit with a non-zero status code if an exception is t=
hrown.
+                (dynamic-wind
+                  (const #t)
+                  (lambda ()
+                    (setgid (passwd:gid user))
+                    (setuid (passwd:uid user))
+                    (primitive-exit
+                     (apply system*
+                            initdb
+                            "-D"
+                            #$data-directory
+                            initdb-args)))
+                  (lambda ()
+                    (primitive-exit 1))))
+               (pid (waitpid pid)))))))))
=20
 (define postgresql-shepherd-service
   (match-lambda
--=20
2.20.1 (Apple Git-117)





Acknowledgement sent to Robert Vollmert <rob@HIDDEN>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#36451; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.