crowdsecurity/crowdsec · error

starting crowdsec daemon: %w

Error message

starting crowdsec daemon: %w

What it means

RunWithNucleiTemplate starts the crowdsec daemon as a child process with the test's config. If the process cannot even be started (Start() fails), the test aborts with this error. It is a process-launch failure, not a crowdsec startup failure.

Source

Thrown at pkg/hubtest/hubtest_item.go:372

	cscliBouncerCmd.Dir = testPath
	cscliBouncerCmd.Env = []string{"TESTDIR=" + testPath, "DATADIR=" + t.RuntimeHubConfig.InstallDataDir, "TZ=UTC"}

	output, err = cscliBouncerCmd.CombinedOutput()
	if err != nil {
		if !strings.Contains(string(output), "unable to create bouncer: bouncer appsectests already exists") {
			fmt.Fprintln(os.Stdout, string(output))
			return fmt.Errorf("fail to run '%s' for test '%s': %w", cscliRegisterCmd.String(), t.Name, err)
		}
	}

	// start crowdsec service
	cmdArgs = []string{"-c", t.RuntimeConfigFilePath}
	crowdsecDaemon := exec.CommandContext(ctx, t.CrowdSecPath, cmdArgs...)
	crowdsecDaemon.Dir = testPath
	crowdsecDaemon.Env = []string{"TESTDIR=" + testPath, "DATADIR=" + t.RuntimeHubConfig.InstallDataDir, "TZ=UTC"}

	if err := crowdsecDaemon.Start(); err != nil {
		return fmt.Errorf("starting crowdsec daemon: %w", err)
	}

	// wait for the appsec port to be available
	if _, err = IsAlive(ctx, t.AppSecHost); err != nil {
		crowdsecLog, err2 := os.ReadFile(crowdsecLogFile)
		if err2 != nil {
			log.Errorf("unable to read crowdsec log file '%s': %s", crowdsecLogFile, err)
		} else {
			log.Errorf("crowdsec log file '%s'", crowdsecLogFile)
			log.Errorf("%s\n", string(crowdsecLog))
		}

		return fmt.Errorf("appsec is down: %w", err)
	}

	// check if the target is available
	nucleiTargetParsedURL, err := url.Parse(t.NucleiTargetHost)
	if err != nil {

View on GitHub (pinned to 909b515798)

Solutions

  1. Build the binaries first (`make build`) so t.CrowdSecPath points at an executable crowdsec
  2. Check the CrowdSecPath is correct and executable (chmod +x / correct test env setup via scripts/test_env.sh)
  3. Verify the test directory (testPath) exists as the daemon's working directory

Example fix

// before
crowdsecDaemon := exec.CommandContext(ctx, t.CrowdSecPath, cmdArgs...)
// after
// ensure binary exists before starting:
if _, err := os.Stat(t.CrowdSecPath); err != nil { return fmt.Errorf("crowdsec binary missing at %s: %w", t.CrowdSecPath, err) }
Defensive patterns

Strategy: validation

Validate before calling

if info, err := os.Stat(crowdsecPath); err != nil || info.IsDir() || info.Mode()&0o111 == 0 {
	t.Fatalf("crowdsec binary missing or not executable at %s", crowdsecPath)
}

Prevention

When it happens

Trigger: crowdsecDaemon.Start() fails: t.CrowdSecPath binary missing or not executable, testPath working directory nonexistent, or fork/exec resource errors.

Common situations: Built crowdsec binary not present at the expected path (forgot `make build` before running hubtests); test directory removed between steps; running in a restricted container without exec permissions.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/3eea77abf1859f53. Report an issue: GitHub.