guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: services: postgresql-roles: Fix race condition.


From: guix-commits
Subject: 01/03: services: postgresql-roles: Fix race condition.
Date: Tue, 23 Feb 2021 05:27:10 -0500 (EST)

mothacehe pushed a commit to branch master
in repository guix.

commit 1a8cfb6d4c767d6cb19689404d7d0bca336ed0d6
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Tue Feb 23 11:00:18 2021 +0100

    services: postgresql-roles: Fix race condition.
    
    Make sure that the postgresql-roles script is completed before declaring the
    postgresql-roles service as started.
    
    * gnu/services/databases.scm (postgresql-create-roles): Return the command
    line instead of a program-file.
    (postgresql-role-shepherd-service): Use fork+exec-command to start the role
    creation script and wait for its completion before returning.
---
 gnu/services/databases.scm | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index 91ce503..979f3dd 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -410,13 +410,8 @@ rolname = '" ,name "')) as not_exists;\n"
 
   (let ((host (postgresql-role-configuration-host config))
         (roles (postgresql-role-configuration-roles config)))
-    (program-file
-     "postgresql-create-roles"
-     #~(begin
-         (let ((psql #$(file-append postgresql "/bin/psql")))
-           (execl psql psql "-a"
-                  "-h" #$host
-                  "-f" #$(roles->queries roles)))))))
+    #~(let ((psql #$(file-append postgresql "/bin/psql")))
+        (list psql "-a" "-h" #$host "-f" #$(roles->queries roles)))))
 
 (define (postgresql-role-shepherd-service config)
   (match-record config <postgresql-role-configuration>
@@ -425,10 +420,14 @@ rolname = '" ,name "')) as not_exists;\n"
            (requirement '(postgres))
            (provision '(postgres-roles))
            (one-shot? #t)
-           (start #~(make-forkexec-constructor
-                     (list #$(postgresql-create-roles config))
-                     #:user "postgres" #:group "postgres"
-                     #:log-file #$log))
+           (start
+            #~(lambda args
+                (let ((pid (fork+exec-command
+                            #$(postgresql-create-roles config)
+                            #:user "postgres"
+                            #:group "postgres"
+                            #:log-file #$log)))
+                  (zero? (cdr (waitpid pid))))))
            (documentation "Create PostgreSQL roles.")))))
 
 (define postgresql-role-service-type



reply via email to

[Prev in Thread] Current Thread [Next in Thread]