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.
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: