How to enable systemd on WSL2: Ubuntu 20 and CentOS 8
I have a work-around here but it doesn't work for those services explicitly require systemd:
Still using /init
instead of /sbin/init
on WSL2, works for regular services, not those explicitly require 'systemd'.
Find out where systemctl is:
which systemctl
Use the path to systemctl for the following commands.
Install Python 2 (if not available by default):
sudo dnf install python2 -y
sudo ln -s /usr/bin/python2 /usr/bin/python
Wrap systemctl in Python (or somehow let systemctl work with systemd not on PID 1):
sudo mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py >temp
sudo mv temp /usr/bin/systemctl
sudo chmod +x /usr/bin/systemctl
Test systemctl:
sudo dnf install nginx -y
sudo systemctl start nginx
curl localhost
sudo systemctl stop nginx