wsl2 can't run in the background after enabling systemd

c0febean 😊 0 Reputation points
2023-03-22T15:19:27.2666667+00:00

After I tried to enable systemd, I found that wsl does not run in the background anymore, there must be a window to keep it running, including ssh connections, and it closes automatically in less than a minute.

When I closed systemd, it was able to keep running in the background again.

I've seen similar documentation, but there seems to be a difference between the description and not enabling systemds

https://learn.microsoft.com/en-my/windows/wsl/faq#can-i-use-wsl-for-production-scenarios--

I would like to know how to keep the service running in the background with systemd enabled

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
9,820 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,371 Reputation points
    2023-03-23T15:47:07.2+00:00

    Hello there,

    How did you enable the enable systemd ?

    You can try to disable systemd in conf and manually start systemd using this script and see if that helps

    https://github.com/khs1994-docker/lnmp/blob/9c93d7dbeff6bba96445771cb7cf94d87528d4c0/wsl2/ubuntu-wsl2-systemd-script/enter-systemd-namespace

    Currently, you need a process running that's a child of the Microsoft init (like an interactive shell) to keep WSL from idle-terminating. If you don't want to leave something open, you can always nohup something.

    This may change in future; there's an issue open about it here: https://github.com/microsoft/WSL/issues/8854

    MS's suggested solution for this request is that you start a tmux session and leave it running. You can even easily automate this.

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.