From 29d49ba31adfe4703c96572f31b1a9c4c3227dc3 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 9 Jun 2023 13:27:12 +0100 Subject: Detach the database setup from the main guix-data-service process This will allow restarting them independently, leaving it up to the operator to ensure that all processes are compatible. --- scripts/guix-data-service-process-jobs.in | 2 ++ scripts/guix-data-service.in | 52 ++----------------------------- 2 files changed, 4 insertions(+), 50 deletions(-) (limited to 'scripts') diff --git a/scripts/guix-data-service-process-jobs.in b/scripts/guix-data-service-process-jobs.in index fb0385e..6ad1ec9 100644 --- a/scripts/guix-data-service-process-jobs.in +++ b/scripts/guix-data-service-process-jobs.in @@ -65,6 +65,8 @@ %default-options)) (let ((opts (parse-options (cdr (program-arguments))))) + (run-sqitch) + (with-postgresql-connection "process-jobs" (lambda (conn) diff --git a/scripts/guix-data-service.in b/scripts/guix-data-service.in index 1398aa0..6a41413 100644 --- a/scripts/guix-data-service.in +++ b/scripts/guix-data-service.in @@ -234,57 +234,9 @@ (simple-format port "~A\n" (getpid))))) (when (assoc-ref opts 'update-database) - (let ((command - (list (%config 'sqitch) - "deploy" - "--db-client" (%config 'sqitch-psql) - ;; For some reason, sqitch behaves differently when the - ;; guix-data-service is packaged, and when it's not, so try - ;; and hack around this here. - "--chdir" (let ((base (dirname (%config 'sqitch-plan)))) - (if (string-prefix? "/gnu" (%config 'sqitch-plan)) - base - (dirname base))) - "--plan-file" (%config 'sqitch-plan) - "--mode" "change" ; this helps when migrations don't - ; have the revert bit implemented - (let* ((database-config (get-database-config)) - (params (string-join - (map - (match-lambda - ((key . val) - (string-append key "=" val))) - (filter - (match-lambda - ((key . _) - (not (member key '("user" - "host" - "dbname"))))) - database-config)) - "&"))) - (string-append "db:pg://" - (assoc-ref database-config "user") - "@" - (if (string=? (assoc-ref database-config "host") - "localhost") - "" ; This means the unix socket - ; connection will be used - (assoc-ref database-config "host")) - "/" - (assoc-ref database-config "dbname") - (if (string-null? params) - "" - "?") - params))))) - (simple-format #t "running command: ~A\n" - (string-join command)) - (unless (zero? (apply system* command)) - (simple-format - (current-error-port) - "error: sqitch command failed\n") - (exit 1)) + (run-sqitch) - (atomic-box-set! startup-completed #t))) + (atomic-box-set! startup-completed #t)) (call-with-new-thread (lambda () -- cgit v1.2.3