Systemd with WSL2 but not really

As WSL currently does not have official systemd support (although in the future that might come) I stumbled across an interesting GitHub project by GitHub@kvaps which takes the usual systemctl commands and replaces them with a bash script.

Systemd with WSL2 but not really

Just a short article about fake systemd with WSL2.

As WSL currently does not have official systemd support (although in the future that might come) I stumbled across an interesting GitHub project by GitHub@kvaps which takes the usual systemctl commands and replaces them with a bash script.

So where you might have used 'systemctl start apache2' the systemctl part is an extra script that handles the start command a little differently than the original. It makes direct use of the 'start-stop-daemon' to start and stop your processes in the background.

Now I have adjusted the script a little so that enabled services on your WSL instance and some LXC containers (at least most Turnkey containers) will auto-start when the console is opened:

This actually works surprisingly well. With the Turnkey WordPress 16.1 container I tried, I could actually manage an easy setup. The only thing I had to block was following services that interrupted the WSL startup or networking in some kind:

networking.service
rsyslog.service
inithooks.service
shellinabox.service
*stunnel4*
rsync.service

You can try this with v1.0.0 of my project bostrot/wsl2-distro-manager: A GUI to quickly manage your WSL2 instances (github.com).

Select an LXC container (e.g. Turnkey Wordpress 16.1):

After downloading and creating the instance you will see the following message:

This is the part where my fork of fake-systemd is installed on the new instance.

After everything is done and you start the instance for the first time you get prompted to enter the default passwords as it is the default with turnkey containers. With the first start it actually starts with the `turnkey-init` command instead of the normal console so that we get the following:

And voilà, wordpress installed on wsl:

Buy WSL Manager - Microsoft Store
A quick way to manage your WSL instances with a GUI.Copy, rename, create, download and use custom rootfs files with WSL in a GUI. Open Source: https://github.com/bostrot/wsl2-distro-manager
GitHub - bostrot/wsl2-distro-manager: A GUI to quickly manage your WSL2 instances
A GUI to quickly manage your WSL2 instances. Contribute to bostrot/wsl2-distro-manager development by creating an account on GitHub.

Subscribe to Senpai.Club

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe