chenhg5/cc-connect · error

systemd user session not available. This often happens whe

Error message

systemd user session not available.
  This often happens when connecting via SSH without a systemd login session.
  Try one of:
    1. Run as root: sudo cc-connect daemon install (uses system-level systemd)
    2. loginctl enable-linger %s && export XDG_RUNTIME_DIR=/run/user/$(id -u)
    3. Use nohup/tmux instead: nohup cc-connect > cc-connect.log 2>&1 &

What it means

cc-connect installs its daemon as a systemd *user* unit on Linux, which requires an active systemd user session for the current user. This error is thrown when the user-level systemd manager is unreachable even though system systemd is running — classically over SSH, where no PAM login session (and thus no /run/user/<uid> bus) is created. The message lists three concrete remediations including running at system level with sudo, enabling linger, or falling back to nohup/tmux.

Source

Thrown at daemon/systemd.go:302

				"  If running in a container, systemd is typically not available.\n"+
				"  Use nohup, tmux, or screen instead:\n"+
				"    nohup cc-connect > cc-connect.log 2>&1 &", state)
		}
		return fmt.Errorf("systemd check failed (state: %s).\n"+
			"  Use nohup as alternative: nohup cc-connect > cc-connect.log 2>&1 &", state)
	}

	// User-level failures
	if wsl {
		return fmt.Errorf("systemd user session not available in WSL2.\n" +
			"  Add the following to /etc/wsl.conf and restart WSL (wsl --shutdown):\n" +
			"    [boot]\n" +
			"    systemd=true\n" +
			"  Or use: nohup cc-connect > cc-connect.log 2>&1 &")
	}

	user := os.Getenv("USER")
	return fmt.Errorf("systemd user session not available.\n"+
		"  This often happens when connecting via SSH without a systemd login session.\n"+
		"  Try one of:\n"+
		"    1. Run as root: sudo cc-connect daemon install (uses system-level systemd)\n"+
		"    2. loginctl enable-linger %s && export XDG_RUNTIME_DIR=/run/user/$(id -u)\n"+
		"    3. Use nohup/tmux instead: nohup cc-connect > cc-connect.log 2>&1 &", user)
}

func isWSL2() bool {
	data, err := os.ReadFile("/proc/version")
	if err != nil {
		return false
	}
	lower := strings.ToLower(string(data))
	return strings.Contains(lower, "microsoft") || strings.Contains(lower, "wsl")
}

func parseKeyValue(text string) map[string]string {
	m := make(map[string]string)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Enable linger so the user manager runs without login: `sudo loginctl enable-linger $USER`
  2. Ensure the session bus env is set: `export XDG_RUNTIME_DIR=/run/user/$(id -u)` (and `export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus`), then retry
  3. Install at system level instead: `sudo cc-connect daemon install`
  4. Use `nohup cc-connect > cc-connect.log 2>&1 &` or tmux if systemd user sessions are intentionally disabled on the host

Example fix

// before: over SSH
$ cc-connect daemon install
// error: systemd user session not available
// after
$ sudo loginctl enable-linger $USER
$ export XDG_RUNTIME_DIR=/run/user/$(id -u)
$ cc-connect daemon install
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$XDG_RUNTIME_DIR" ] || [ ! -d "$XDG_RUNTIME_DIR" ]; then
  sudo loginctl enable-linger "$USER"
  export XDG_RUNTIME_DIR=/run/user/$(id -u)
fi
systemctl --user status >/dev/null 2>&1 || { echo "no systemd user session; use sudo cc-connect daemon install"; exit 1; }
cc-connect daemon install

Try / catch

if err := daemon.Install(cfg); err != nil && strings.Contains(err.Error(), "user session not available") {
    // escalate to system-level install or fall back to nohup
    return runPrivilegedInstallOrNohup(cfg)
}

Prevention

When it happens

Trigger: `cc-connect daemon install` over an SSH session (or cron/su without full PAM session) where XDG_RUNTIME_DIR is unset and `systemctl --user` fails with "Failed to connect to bus"; or where the user has no lingering session so the user manager only exists during graphical login.

Common situations: SSH into a headless server and trying to install the daemon; switching users with `su` (loses the systemd session); deploying via CI/SSH scripts; user account created without a login session ever started.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/886a9ed108bb93c3. Report an issue: GitHub.