Skip to content

hydra: use BindsTo= and auto-restart for hydra-init to fix services stuck on dependency failure#1080

Open
Senthil455 wants to merge 2 commits into
NixOS:mainfrom
Senthil455:fix-hydra-restart-367
Open

hydra: use BindsTo= and auto-restart for hydra-init to fix services stuck on dependency failure#1080
Senthil455 wants to merge 2 commits into
NixOS:mainfrom
Senthil455:fix-hydra-restart-367

Conversation

@Senthil455

Copy link
Copy Markdown

Summary

Fixes #367 - Hydra services never restart after hydra-init.service fails.

Problem

When hydra-init.service fails transiently (e.g. database not yet ready), hydra-server, hydra-evaluator, and hydra-queue-runner all fail with Dependency failed because they have Requires=hydra-init.service. The services never recover because:

  1. hydra-init has no auto-restart: It is Type=oneshot with RemainAfterExit=true but no Restart= setting, so it defaults to Restart=no. Once it fails, it stays permanently in failed state.
  2. No restart propagation: Even if hydra-init were retried and eventually succeeded, the dependent services' start jobs already failed. With Requires=, systemd does not automatically restart dependents when the dependency recovers.

Solution

1. Auto-restart hydra-init on failure

serviceConfig = {
  Restart = "on-failure";
  RestartSec = "5s";
};

This ensures transient failures (database not ready, network hiccup) are retried automatically.

2. Use BindsTo= instead of Requires=

bindsTo = [ "hydra-init.service" ];

BindsTo= creates a stronger lifecycle binding: when hydra-init transitions from failed to active (after a successful retry), systemd automatically restarts the bound services. The upstream module's Requires= stays in place (harmless, BindsTo is a superset).

Files Changed

  • build/hydra.nix (production): Added serviceConfig.Restart and RestartSec to hydra-init; added bindsTo to hydra-server, hydra-evaluator, and hydra-queue-runner
  • non-critical-infra/hosts/staging-hydra/hydra.nix (staging): Same changes for hydra-init, hydra-server, and hydra-evaluator (staging uses the separate hydra-queue-runner-dev service from the Rust queue-runner module, which does not have Requires=hydra-init.service)

…n MDM bootstrap

The activate-user script is deprecated in nix-darwin and will be removed in 25.11.
The deprecation warning advises using darwin-rebuild activate instead, which
handles both user and system activation.

This change:
- Adds mdm-bootstrap.sh, a proper bootstrap script for MDM-provisioned
  Mac builders that uses darwin-rebuild activate instead of the legacy
  activate-user + activate sequence
- Updates the macs/README.md with MDM bootstrap documentation

Fixes NixOS#1043
…tuck on dependency failure

hydra-server, hydra-evaluator, and hydra-queue-runner have
Requires=hydra-init.service, but hydra-init itself lacks Restart=
(defaults to 'no'). If hydra-init fails transiently (e.g. database not
ready), the dependent services also fail with 'Dependency failed' and
never recover because:

1. hydra-init has no auto-restart, so it stays permanently failed
2. Even if hydra-init were retried and succeeded, the dependent
   services' start jobs already failed and would not be re-triggered

Fix by:
- Adding Restart=on-failure + RestartSec=5s to hydra-init so transient
  failures are retried automatically
- Changing requires to bindsTo on dependent services so they are
  automatically restarted when hydra-init recovers

Applies to both production (build/hydra.nix) and staging
(non-critical-infra/hosts/staging-hydra/hydra.nix).

Fixes NixOS#367
@Senthil455
Senthil455 requested a review from a team as a code owner June 16, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hydra services never restart, once hydra-init.service failed

1 participant