AdguardTeam/AdGuardHome · error

getting current directory: %w

Error message

getting current directory: %w

What it means

handleRun failed to obtain the current working directory with os.Getwd before building the service configuration. On Unix this fails when the process's cwd has been deleted or is unreadable.

Source

Thrown at internal/home/service.go:99

	p.logger.InfoContext(p.ctx, "stopping: waiting for cleanup")

	aghos.SendShutdownSignal(p.signals)

	// Wait for other goroutines to complete their job.
	<-p.done

	return nil
}

// handleRun runs p.
func (p *program) handleRun(
	ctx context.Context,
	baseLogger *slog.Logger,
	opts options,
) (err error) {
	pwd, err := os.Getwd()
	if err != nil {
		return fmt.Errorf("getting current directory: %w", err)
	}

	args := optsToArgs(opts)
	baseLogger.DebugContext(ctx, "using", "args", args)

	svcConfig := &service.Config{
		Name:             serviceName,
		DisplayName:      serviceDisplayName,
		Description:      serviceDescription,
		WorkingDirectory: pwd,
		Arguments:        args,
	}
	ossvc.ConfigureServiceOptions(svcConfig, p.clock.Now(), version.Full())

	s, err := service.New(p, svcConfig)
	if err != nil {
		return fmt.Errorf("initializing service: %w", err)
	}

View on GitHub (pinned to b41aefbe51)

Solutions

  1. cd into a stable directory (e.g. /var/lib/adguardhome) before running the service action
  2. Restart the shell/process if its cwd was deleted
  3. In containers, set a persistent WORKDIR in the image

Example fix

# before
cd /tmp/build-123 && ./AdGuardHome -s run

# after
cd /var/lib/adguardhome && ./AdGuardHome -s run
Defensive patterns

Strategy: validation

Validate before calling

if pwd, err := os.Getwd(); err != nil {
    os.Chdir("/var/lib/adguardhome") // recover to a stable cwd
}

Prevention

When it happens

Trigger: Running the 'service run' control action from a directory that was removed after the shell/process started, or in containers where the workdir was deleted or replaced.

Common situations: Starting AdGuard Home from a temp/build directory that gets cleaned up, or container setups where the working directory is an overlay that vanished.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/e358f5e3609bbec7. Report an issue: GitHub.