From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:38085) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhgsl-0002nN-2p for guix-patches@gnu.org; Sun, 30 Jun 2019 16:57:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhgsj-00026s-RZ for guix-patches@gnu.org; Sun, 30 Jun 2019 16:57:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33821) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hhgsj-00026k-OQ for guix-patches@gnu.org; Sun, 30 Jun 2019 16:57:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hhgsh-0006Gb-Pw for guix-patches@gnu.org; Sun, 30 Jun 2019 16:57:05 -0400 Subject: [bug#36451] [PATCH] gnu: services: postgresql: Don't initdb when directory exists Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:37988) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhgsW-0002gu-Pw for guix-patches@gnu.org; Sun, 30 Jun 2019 16:56:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhgsU-0001ky-0D for guix-patches@gnu.org; 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 ) id 1hhgsT-0001gs-Bx for guix-patches@gnu.org; Sun, 30 Jun 2019 16:56:49 -0400 From: Robert Vollmert Date: Sun, 30 Jun 2019 22:56:42 +0200 Message-Id: <20190630205642.54866-1-rob@vllmrt.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 36451@debbugs.gnu.org Cc: Robert Vollmert * 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)