From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id wM1vG9z76mWo1gAA62LTzQ:P1 (envelope-from ) for ; Fri, 08 Mar 2024 12:51:56 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id wM1vG9z76mWo1gAA62LTzQ (envelope-from ) for ; Fri, 08 Mar 2024 12:51:56 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1709898716; 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; bh=iwoDv6qBxi853fVuGjLOkASGyp1PrOQI6cBQO277quY=; b=ZrkjTQjdcrszxljAgrLSONrGyzSNVj/oSshqwJF6gw2Hp3FUp7BVdApX061W04qOWqaaPE KEiP7R/o3xVl/BgLoj3yboKZg4xPyrMWiiXznrkFOiJRQQ4rS/PFf/UK0m9lhx1VyA5i6k 3maMaVIN61yVkbYOeEA54E3IxQK6/Eqwj4ZVCa0WwRwo8+6D/ZiR1aDogIiG5HQvemX4oi nKEG+NMmTvp1jopQVtorYaEyNhPZLMC3lczJ2xOs4vhUxGsjj2EEyczEmQLydXTl9TFxx9 D88xZ2ET4skN908eXQK6jqVk5KGFgJKWr9FzVXhHC52oV0SbQWxVl4JofWsisQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1709898716; a=rsa-sha256; cv=none; b=k+6wfoqp8tRREecgNOlP5A87VDbjZEMtNauegLmmq+ECub92v4nOV81TD7bnW5Q4kCRoBB RYqIlVF76q6yi0LkGQzjQOCe9FHOSpMIB+70YfdCkvi0AHSzH/1UWltBUiwlwORj0lWp4P 0E6aCLFunrqmbm6SqC443XHbypIFgb0UvYdeXzqoLSgDBJyHRMlfCHERg5T563Ftk9ZSFo 1Dd5i+YE8LEpQlHg91ZDo/TVQB7W6gG7JG/NRylw3lJqhyB8zG3cZIeGBB+L0mWgWP3Ne9 QAsC/oPa+kQYh/TSCryYPyLA/JFkH56JhdrUSMeZk7R96DvObQnCayQE4SFuBw== 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 2DCC51144F for ; Fri, 8 Mar 2024 12:51:56 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riYlA-00081b-Ab; Fri, 08 Mar 2024 06:51:32 -0500 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 1riYl9-00081I-8b for guix-patches@gnu.org; Fri, 08 Mar 2024 06:51:31 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riYl9-0006A1-0W for guix-patches@gnu.org; Fri, 08 Mar 2024 06:51:31 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1riYle-000491-Rp for guix-patches@gnu.org; Fri, 08 Mar 2024 06:52:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#36451] [PATCH v2] gnu: services: postgresql: Don't initdb when directory exists References: <20190630205642.54866-1-rob@vllmrt.net> In-Reply-To: <20190630205642.54866-1-rob@vllmrt.net> Resent-From: Dale Mellor Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 08 Mar 2024 11:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36451 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 36451@debbugs.gnu.org Cc: guix-devel-0brg6b@rdmp.org, rob@vllmrt.net X-Debbugs-Original-Cc: Dale Mellor , guix-patches@gnu.org, Robert Vollmert Received: via spool by 36451-submit@debbugs.gnu.org id=B36451.170989871015886 (code B ref 36451); Fri, 08 Mar 2024 11:52:02 +0000 Received: (at 36451) by debbugs.gnu.org; 8 Mar 2024 11:51:50 +0000 Received: from localhost ([127.0.0.1]:56916 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1riYlR-00048A-RJ for submit@debbugs.gnu.org; Fri, 08 Mar 2024 06:51:50 -0500 Received: from [195.15.247.228] (port=40448 helo=rdmp.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1riYlM-00047t-Vk for 36451@debbugs.gnu.org; Fri, 08 Mar 2024 06:51:49 -0500 Received: from [127.0.0.1] (helo=localhost.localdomain) by rdmp.org with esmtp (Exim 4.96.1) (envelope-from ) id 1riYkA-0004q8-1C; Fri, 08 Mar 2024 11:51:06 +0000 From: Dale Mellor Date: Fri, 8 Mar 2024 11:51:01 +0000 Message-ID: <20240308115101.2047407-1-guix-devel-0brg6b@rdmp.org> X-Mailer: git-send-email 2.41.0 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: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -4.78 X-Spam-Score: -4.78 X-Migadu-Queue-Id: 2DCC51144F X-Migadu-Scanner: mx13.migadu.com X-TUID: Z4ZMYGC27p41 From: Robert Vollmert * gnu/services/databases.scm (postgresql-activation): Check if directory exists. -------------- Dale Mellor: - Modified to make patch apply to head of current master branch. - Verified working, does not break an existing system. - Code change is clean. Reviewed-by: Dale Mellor --- gnu/services/databases.scm | 68 ++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index 580031cb423..cb85d18e214 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -235,20 +235,7 @@ (define postgresql-activation (use-modules (guix build utils) (ice-9 match)) - (let ((user (getpwnam "postgres")) - (initdb (string-append - #$(final-postgresql postgresql - extension-packages) - "/bin/initdb")) - (initdb-args - (append - (if #$locale - (list (string-append "--locale=" #$locale)) - '())))) - ;; Create db state directory. - (mkdir-p #$data-directory) - (chown #$data-directory (passwd:uid user) (passwd:gid user)) - + (let ((user (getpwnam "postgres"))) ;; Create the socket directory. (let ((socket-directory #$(postgresql-config-file-socket-directory config-file))) @@ -261,25 +248,40 @@ (define postgresql-activation (mkdir-p #$log-directory) (chown #$log-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 thrown. - (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)))))))) + (unless (file-exists? #$data-directory) + (let ((initdb (string-append + #$(final-postgresql postgresql + extension-packages) + "/bin/initdb")) + (initdb-args + (append + (if #$locale + (list (string-append "--locale=" #$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 + ;; thrown. + (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)))))))))) (define postgresql-shepherd-service (match-lambda -- 2.41.0