microsoft / microsoft/WSL

wsl executes any command specified/starts shell before systemd has initialized, when starting instance

Open
#8,886 7 comments 3 reactions 0 assignees View on GitHub
feature
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

**Is your feature request related to a problem? Please describe.**
When a WSL instance with systemd support enabled is started (either with `wsl` or `wsl `), the shell inside the instance is started immediately, without waiting for systemd to have initialized (reached running state) and indeed without even waiting for the system dbus to be available. This is far earlier than native Linux provides a login prompt (_getty.target_ and _systemd-logind.service_ are both called upon by _multi-user.target_.)

This means that if you are using systemd support in a way that involved heavy use of systemd services (and commands relating to same), there is a good chance that initial commands will fail. To pick a trivial example, `wsl systemctl is-system-running` usually errors out unless the WSL instance has already started.

**Describe the solution you'd like**
When systemd support is enabled, by default, wsl.exe should hold any further actions (executing commands or starting shells) until systemd has reached the _running_ or _degraded_ state (as described by `systemctl is-system-running`) to ensure commands behave as they would on native Linux and novel failure modes aren't introduced.

(This should be overridable for debugging purposes, ideally with a wsl.exe command-line option; a suitably lengthy or configurable timeout might also be useful.)

**Describe alternatives you've considered**
For compatibility with WSL as-it-is, this could be an option to be enabled in /etc/wsl.conf.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing `wsl systemctl is-system-running` during instance startup and compare behavior with a plain `wsl` shell. Read the WSL startup path for `wsl.exe` command execution, the systemd readiness states, and the `/etc/wsl.conf` compatibility option described here. Done means commands and shells wait for `running` or `degraded`, with the requested override or timeout behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.