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.master
parent
bebcf97600
commit
1a8cfb6d4c
|
@ -410,13 +410,8 @@ rolname = '" ,name "')) as not_exists;\n"
|
||||||
|
|
||||||
(let ((host (postgresql-role-configuration-host config))
|
(let ((host (postgresql-role-configuration-host config))
|
||||||
(roles (postgresql-role-configuration-roles config)))
|
(roles (postgresql-role-configuration-roles config)))
|
||||||
(program-file
|
#~(let ((psql #$(file-append postgresql "/bin/psql")))
|
||||||
"postgresql-create-roles"
|
(list psql "-a" "-h" #$host "-f" #$(roles->queries roles)))))
|
||||||
#~(begin
|
|
||||||
(let ((psql #$(file-append postgresql "/bin/psql")))
|
|
||||||
(execl psql psql "-a"
|
|
||||||
"-h" #$host
|
|
||||||
"-f" #$(roles->queries roles)))))))
|
|
||||||
|
|
||||||
(define (postgresql-role-shepherd-service config)
|
(define (postgresql-role-shepherd-service config)
|
||||||
(match-record config <postgresql-role-configuration>
|
(match-record config <postgresql-role-configuration>
|
||||||
|
@ -425,10 +420,14 @@ rolname = '" ,name "')) as not_exists;\n"
|
||||||
(requirement '(postgres))
|
(requirement '(postgres))
|
||||||
(provision '(postgres-roles))
|
(provision '(postgres-roles))
|
||||||
(one-shot? #t)
|
(one-shot? #t)
|
||||||
(start #~(make-forkexec-constructor
|
(start
|
||||||
(list #$(postgresql-create-roles config))
|
#~(lambda args
|
||||||
#:user "postgres" #:group "postgres"
|
(let ((pid (fork+exec-command
|
||||||
#:log-file #$log))
|
#$(postgresql-create-roles config)
|
||||||
|
#:user "postgres"
|
||||||
|
#:group "postgres"
|
||||||
|
#:log-file #$log)))
|
||||||
|
(zero? (cdr (waitpid pid))))))
|
||||||
(documentation "Create PostgreSQL roles.")))))
|
(documentation "Create PostgreSQL roles.")))))
|
||||||
|
|
||||||
(define postgresql-role-service-type
|
(define postgresql-role-service-type
|
||||||
|
|
Reference in New Issue