From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id TTYFFJ5hBWAUTgAA0tVLHw (envelope-from ) for ; Mon, 18 Jan 2021 10:23:26 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 0VtpD55hBWAmfwAAB5/wlQ (envelope-from ) for ; Mon, 18 Jan 2021 10:23:26 +0000 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 961CA940501 for ; Mon, 18 Jan 2021 10:23:24 +0000 (UTC) Received: from localhost ([::1]:48828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1Rgx-0001bU-J2 for larch@yhetil.org; Mon, 18 Jan 2021 05:23:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Rbr-0005x9-4E for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:08 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1Rbn-0006kj-FM for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1Rbn-0005KW-BK for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45860] [PATCH v2 3/5] services: postgresql: Add log directory support. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 18 Jan 2021 10:18:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45860 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 45860@debbugs.gnu.org Received: via spool by 45860-submit@debbugs.gnu.org id=B45860.161096502920385 (code B ref 45860); Mon, 18 Jan 2021 10:18:03 +0000 Received: (at 45860) by debbugs.gnu.org; 18 Jan 2021 10:17:09 +0000 Received: from localhost ([127.0.0.1]:46416 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Rau-0005Ic-I8 for submit@debbugs.gnu.org; Mon, 18 Jan 2021 05:17:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39574) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Ram-0005H9-S0 for 45860@debbugs.gnu.org; Mon, 18 Jan 2021 05:17:03 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:52246) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1Rah-0006DN-Mc; Mon, 18 Jan 2021 05:16:55 -0500 Received: from [2a01:e0a:19b:d9a0:1538:87ab:3a95:7600] (port=55432 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l1Rag-0001QJ-RX; Mon, 18 Jan 2021 05:16:55 -0500 From: Mathieu Othacehe Date: Mon, 18 Jan 2021 11:16:26 +0100 Message-Id: <20210118101628.202607-4-othacehe@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118101628.202607-1-othacehe@gnu.org> References: <20210118101628.202607-1-othacehe@gnu.org> 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: , Cc: Mathieu Othacehe Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 3.64 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 961CA940501 X-Spam-Score: 3.64 X-Migadu-Scanner: scn0.migadu.com X-TUID: q9ZU+ujv1h5H * gnu/services/databases.scm (postgresql-configuration-log-directory): New procedure. ()[log-directory]: New field. (postgresql-activation): Create the log directory. (postgresql-shepherd-service): Honor it. * gnu/tests/databases.scm (%postgresql-log-directory): New variable. (log-file): New test case. * doc/guix.texi (Database Services): Document it. --- doc/guix.texi | 5 +++++ gnu/services/databases.scm | 36 ++++++++++++++++++++++++++++-------- gnu/tests/databases.scm | 20 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 46039d26d0..22674e2804 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19316,6 +19316,11 @@ The configuration file to use when running PostgreSQL. The default behaviour uses the postgresql-config-file record with the default values for the fields. +@item @code{log-directory} (default: @code{"/var/log/postgresql"}) +The directory where @command{pg_ctl} output will be written in a file +named @code{"pg_ctl.log"}. This file can be useful to debug PostgreSQL +configuration errors for instance. + @item @code{data-directory} (default: @code{"/var/lib/postgresql/data"}) Directory in which to store the data. diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index 83dee52cf3..c387a7da6c 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -52,6 +52,7 @@ postgresql-configuration-port postgresql-configuration-locale postgresql-configuration-file + postgresql-configuration-log-directory postgresql-configuration-data-directory postgresql-service @@ -164,6 +165,8 @@ host all all ::1/128 md5")) (default "en_US.utf8")) (config-file postgresql-configuration-file (default (postgresql-config-file))) + (log-directory postgresql-configuration-log-directory + (default "/var/log/postgresql")) (data-directory postgresql-configuration-data-directory (default "/var/lib/postgresql/data")) (extension-packages postgresql-configuration-extension-packages @@ -200,15 +203,18 @@ host all all ::1/128 md5")) (define postgresql-activation (match-lambda - (($ postgresql port locale config-file data-directory - extension-packages) + (($ postgresql port locale config-file + log-directory data-directory + extension-packages) #~(begin (use-modules (guix build utils) (ice-9 match)) (let ((user (getpwnam "postgres")) - (initdb (string-append #$(final-postgresql postgresql extension-packages) - "/bin/initdb")) + (initdb (string-append + #$(final-postgresql postgresql + extension-packages) + "/bin/initdb")) (initdb-args (append (if #$locale @@ -225,6 +231,11 @@ host all all ::1/128 md5")) (mkdir-p socket-directory) (chown socket-directory (passwd:uid user) (passwd:gid user)))) + ;; Create the log directory. + (when (string? #$log-directory) + (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) @@ -247,8 +258,9 @@ host all all ::1/128 md5")) (define postgresql-shepherd-service (match-lambda - (($ postgresql port locale config-file data-directory - extension-packages) + (($ postgresql port locale config-file + log-directory data-directory + extension-packages) (let* ((pg_ctl-wrapper ;; Wrapper script that switches to the 'postgres' user before ;; launching daemon. @@ -260,13 +272,21 @@ host all all ::1/128 md5")) (match (command-line) ((_ mode) (let ((user (getpwnam "postgres")) - (pg_ctl #$(file-append (final-postgresql postgresql extension-packages) + (pg_ctl #$(file-append + (final-postgresql postgresql + extension-packages) "/bin/pg_ctl")) (options (format #f "--config-file=~a -p ~d" #$config-file #$port))) (setgid (passwd:gid user)) (setuid (passwd:uid user)) - (execl pg_ctl pg_ctl "-D" #$data-directory "-o" options + (execl pg_ctl pg_ctl "-D" #$data-directory + #$@(if (string? log-directory) + (list "-l" + (string-append log-directory + "/pg_ctl.log")) + '()) + "-o" options mode))))))) (pid-file (in-vicinity data-directory "postmaster.pid")) (action (lambda args diff --git a/gnu/tests/databases.scm b/gnu/tests/databases.scm index 7338007919..d881a8c3ee 100644 --- a/gnu/tests/databases.scm +++ b/gnu/tests/databases.scm @@ -214,6 +214,9 @@ ;;; The PostgreSQL service. ;;; +(define %postgresql-log-directory + "/var/log/postgresql") + (define %postgresql-os (simple-operating-system (service postgresql-service-type @@ -262,6 +265,23 @@ (start-service 'postgres)) marionette)) + (test-assert "log-file" + (marionette-eval + '(begin + (use-modules (ice-9 ftw) + (ice-9 match)) + (current-output-port + (open-file "/dev/console" "w0")) + (let ((server-log-file + (string-append #$%postgresql-log-directory + "/pg_ctl.log"))) + (and (file-exists? server-log-file) + (display + (call-with-input-file server-log-file + get-string-all))) + #t)) + marionette)) + (test-end) (exit (= (test-runner-fail-count (test-runner-current)) 0))))) -- 2.29.2