From 13ba002dd0be470f182eee16f9e791d76875c771 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 27 Nov 2023 16:45:14 +0100 Subject: [PATCH] nixos/services.gitlab: loosen the coupling between gitlab and postgres/ redis to avoid restarts and races Gitlab stays running at redis and postgresql restarts as if these components were on a different host anyways. Handling reconnetctions is part of the application logic. Co-authored-by: Kim Lindberger for formatting fixes and test failure debugging. --- nixos/modules/services/misc/gitlab.nix | 14 ++++++-------- nixos/tests/gitlab.nix | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/nixos/modules/services/misc/gitlab.nix b/nixos/modules/services/misc/gitlab.nix index 6756d59cf367..ec347a75f063 100644 --- a/nixos/modules/services/misc/gitlab.nix +++ b/nixos/modules/services/misc/gitlab.nix @@ -1386,10 +1386,8 @@ in { systemd.services.gitlab-db-config = { after = [ "gitlab-config.service" "gitlab-postgresql.service" "postgresql.service" ]; - bindsTo = [ - "gitlab-config.service" - ] ++ optional (cfg.databaseHost == "") "postgresql.service" - ++ optional databaseActuallyCreateLocally "gitlab-postgresql.service"; + wants = optional (cfg.databaseHost == "") "postgresql.service" ++ optional databaseActuallyCreateLocally "gitlab-postgresql.service"; + bindsTo = [ "gitlab-config.service" ]; wantedBy = [ "gitlab.target" ]; partOf = [ "gitlab.target" ]; serviceConfig = { @@ -1422,10 +1420,10 @@ in { "gitlab-db-config.service" ]; bindsTo = [ - "redis-gitlab.service" "gitlab-config.service" "gitlab-db-config.service" - ] ++ optional (cfg.databaseHost == "") "postgresql.service"; + ]; + wants = [ "redis-gitlab.service" ] ++ optional (cfg.databaseHost == "") "postgresql.service"; wantedBy = [ "gitlab.target" ]; partOf = [ "gitlab.target" ]; environment = gitlabEnv // (optionalAttrs cfg.sidekiq.memoryKiller.enable { @@ -1612,10 +1610,10 @@ in { "gitlab-db-config.service" ]; bindsTo = [ - "redis-gitlab.service" "gitlab-config.service" "gitlab-db-config.service" - ] ++ optional (cfg.databaseHost == "") "postgresql.service"; + ]; + wants = [ "redis-gitlab.service" ] ++ optional (cfg.databaseHost == "") "postgresql.service"; requiredBy = [ "gitlab.target" ]; partOf = [ "gitlab.target" ]; environment = gitlabEnv; diff --git a/nixos/tests/gitlab.nix b/nixos/tests/gitlab.nix index 8d3126425311..c4d69a56c93a 100644 --- a/nixos/tests/gitlab.nix +++ b/nixos/tests/gitlab.nix @@ -419,7 +419,7 @@ in { gitlab.systemctl("start gitlab-backup.service") gitlab.wait_for_unit("gitlab-backup.service") gitlab.wait_for_file("${nodes.gitlab.services.gitlab.statePath}/backup/dump_gitlab_backup.tar") - gitlab.systemctl("stop postgresql.service gitlab.target") + gitlab.systemctl("stop postgresql.service gitlab-config.service gitlab.target") gitlab.succeed( "find ${nodes.gitlab.services.gitlab.statePath} -mindepth 1 -maxdepth 1 -not -name backup -execdir rm -r {} +" )