lol

nixos/hydra postgresql: Fix #27314 and add test case

authored by

Philipp Steinpass and committed by
Robin Gloster
d784b830 7bba4a16

+47 -8
+2 -2
nixos/modules/services/continuous-integration/hydra/default.nix
··· 270 270 271 271 ${optionalString haveLocalDB '' 272 272 if ! [ -e ${baseDir}/.db-created ]; then 273 - ${config.services.postgresql.package}/bin/createuser hydra 274 - ${config.services.postgresql.package}/bin/createdb -O hydra hydra 273 + ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createuser hydra 274 + ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -O hydra hydra 275 275 touch ${baseDir}/.db-created 276 276 fi 277 277 ''}
+13 -6
nixos/modules/services/databases/postgresql.nix
··· 38 38 39 39 pre84 = versionOlder (builtins.parseDrvName postgresql.name).version "8.4"; 40 40 41 - # NixOS traditionally used `root` as superuser, most other distros use `postgres`. From 17.09 42 - # we also try to follow this standard 43 - superuser = (if versionAtLeast config.system.stateVersion "17.09" then "postgres" else "root"); 44 41 45 42 in 46 43 ··· 151 148 Contents of the <filename>recovery.conf</filename> file. 152 149 ''; 153 150 }; 151 + superUser = mkOption { 152 + type = types.str; 153 + default= if versionAtLeast config.system.stateVersion "17.09" then "postgres" else "root"; 154 + internal = true; 155 + description = '' 156 + NixOS traditionally used `root` as superuser, most other distros use `postgres`. 157 + From 17.09 we also try to follow this standard. Internal since changing this value 158 + would lead to breakage while setting up databases. 159 + ''; 160 + }; 154 161 }; 155 162 156 163 }; ··· 215 222 '' 216 223 # Initialise the database. 217 224 if ! test -e ${cfg.dataDir}/PG_VERSION; then 218 - initdb -U ${superuser} 225 + initdb -U ${cfg.superUser} 219 226 # See postStart! 220 227 touch "${cfg.dataDir}/.first_startup" 221 228 fi ··· 247 254 # Wait for PostgreSQL to be ready to accept connections. 248 255 postStart = 249 256 '' 250 - while ! ${pkgs.sudo}/bin/sudo -u ${superuser} psql --port=${toString cfg.port} -d postgres -c "" 2> /dev/null; do 257 + while ! ${pkgs.sudo}/bin/sudo -u ${cfg.superUser} psql --port=${toString cfg.port} -d postgres -c "" 2> /dev/null; do 251 258 if ! kill -0 "$MAINPID"; then exit 1; fi 252 259 sleep 0.1 253 260 done 254 261 255 262 if test -e "${cfg.dataDir}/.first_startup"; then 256 263 ${optionalString (cfg.initialScript != null) '' 257 - ${pkgs.sudo}/bin/sudo -u ${superuser} psql -f "${cfg.initialScript}" --port=${toString cfg.port} -d postgres 264 + ${pkgs.sudo}/bin/sudo -u ${cfg.superUser} psql -f "${cfg.initialScript}" --port=${toString cfg.port} -d postgres 258 265 ''} 259 266 rm -f "${cfg.dataDir}/.first_startup" 260 267 fi
+32
nixos/tests/hydra.nix
··· 1 + import ./make-test.nix ({ pkgs, ...} : { 2 + name = "hydra-init-localdb"; 3 + meta = with pkgs.stdenv.lib.maintainers; { 4 + maintainers = [ pstn ]; 5 + }; 6 + 7 + machine = 8 + { config, pkgs, ... }: 9 + 10 + { 11 + services.hydra = { 12 + enable = true; 13 + 14 + #Hydra needs those settings to start up, so we add something not harmfull. 15 + hydraURL = "example.com"; 16 + notificationSender = "example@example.com"; 17 + }; 18 + }; 19 + 20 + testScript = 21 + '' 22 + # let the system boot up 23 + $machine->waitForUnit("multi-user.target"); 24 + # test whether the database is running 25 + $machine->succeed("systemctl status postgresql.service"); 26 + # test whether the actual hydra daemons are running 27 + $machine->succeed("systemctl status hydra-queue-runner.service"); 28 + $machine->succeed("systemctl status hydra-init.service"); 29 + $machine->succeed("systemctl status hydra-evaluator.service"); 30 + $machine->succeed("systemctl status hydra-send-stats.service"); 31 + ''; 32 + })