WSL windows subsystem for linux supports Systemd service with versions >= 0.67.6.
Supporting systemd required changes to the WSL architecture. As systemd requires PID 1, the WSL init process started within the Linux distribution becomes a child process of the systemd. Because the WSL init process is responsible for providing the infrastructure for communication between the Linux and Windows components, changing this hierarchy required rethinking some of the assumptions made with the WSL init process. Additional modifications had to be made to ensure a clean shutdown (as that shutdown is controlled by systemd now) and to have compatibility with WSLg, It is also important to note that with these change, systemd services will NOT keep your WSL instance alive.
To enable systemd
– Ensure you are running the right version of WSL: Version 0.67.6 and above
– Set the systemd flag set in your WSL distro settings
This change is only available in the Microsoft Store version of WSL version 0.67.6 and higher.
You can check your version number by running wsl --version. If that command fails then you are running the in-Windows version of WSL and need to upgrade to the Store version
You will need to edit the wsl.conf file to ensure systemd starts up on boot.
Add these lines to the /etc/wsl.conf:
[boot]
systemd=true
restart wsl
close your WSL distro Windows
run wsl.exe --shutdown
Upon launch you should have systemd running. You can check this with the command:
systemctl list-unit-files --type=service
which should show your services’ status.