Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Windows 11 WSL2 completely shuts down when inactive #10157

Closed
1 of 2 tasks
LWJerri opened this issue Jun 2, 2023 · 11 comments
Closed
1 of 2 tasks

[Bug]: Windows 11 WSL2 completely shuts down when inactive #10157

LWJerri opened this issue Jun 2, 2023 · 11 comments

Comments

@LWJerri
Copy link

LWJerri commented Jun 2, 2023

Windows Version

Microsoft Windows [Version 10.0.23471.1000]

WSL Version

Версия WSL: 1.2.5.0 Версия ядра: 5.15.90.1 Версия WSLg: 1.0.51 Версия MSRDC: 1.2.3770 Версия Direct3D: 1.608.2-61064218 Версия DXCore: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Версия Windows: 10.0.23471.1000

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

Linux version 5.15.90.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Jan 27 02:56:13 UTC 2023

Distro Version

Release: 22.04

Other Software

Docker version 24.0.2, build cb74dfc

Repro Steps

  1. Open terminal with WSL2
  2. Close terminal and wait ~1 min.
  3. Open terminal again and run htop and see fresh uptime.

Expected Behavior

WSL should not shut down after some time of inactivity, I did not have this until a complete reinstallation of Windows.

Actual Behavior

WSL turns off completely.

Diagnostic Logs

No response

@LWJerri
Copy link
Author

LWJerri commented Jun 2, 2023

I don't have .wslconfig and my ws.conf:

[boot]
systemd=true

[network]
generateResolvConf=false

@aki-k
Copy link

aki-k commented Jun 6, 2023

@LWJerri This is an intentional design decision by Microsoft. The time is actually just 8 seconds when the instance gets shut down.

You can work around this issue by enabling systemd with https://github.com/DamionGans/ubuntu-wsl2-systemd-script instead of the solution provided by Microsoft.

For Ubuntu 22.04 you also need the patch from DamionGans/ubuntu-wsl2-systemd-script#36 (comment) (the patch goes to the end of enter-systemd-namespace.

You should also change basic.target to multi-user.target in both enter-systemd-namespace and start-systemd-namespace before running "bash ubuntu-wsl2-systemd-script.sh".

@LWJerri
Copy link
Author

LWJerri commented Jun 6, 2023

@LWJerri This is an intentional design decision by Microsoft. The time is actually just 8 seconds when the instance gets shut down.

You can work around this issue by enabling systemd with https://github.com/DamionGans/ubuntu-wsl2-systemd-script instead of the solution provided by Microsoft.

For Ubuntu 22.04 you also need the patch from DamionGans/ubuntu-wsl2-systemd-script#36 (comment) (the patch goes to the end of enter-systemd-namespace.

You should also change basic.target to multi-user.target in both enter-systemd-namespace and start-systemd-namespace before running "bash ubuntu-wsl2-systemd-script.sh".

Hello! Yeap, this solved my problem, thanks!

@LWJerri LWJerri closed this as completed Jun 6, 2023
@aki-k
Copy link

aki-k commented Jun 6, 2023

@LWJerri You could have left this issue open so that Microsoft could've also commented about the problem :)

@LWJerri
Copy link
Author

LWJerri commented Jun 6, 2023

@LWJerri You could have left this issue open so that Microsoft could've also commented about the problem :)

I think it's something out of the realm of impossible, but okay, let's try it.

@LWJerri LWJerri reopened this Jun 6, 2023
@aki-k
Copy link

aki-k commented Jun 6, 2023

btw; you can check with

tasklist | findstr /i "vm wsl"

when the Windows-side processes close down

@ghost
Copy link

ghost commented Jun 6, 2023

This is intentional. If you daemonize some tasks they can keep it running. As long as some number of relay init processes live because they have children the vm should continue to run.

@ghost ghost closed this as completed Jun 6, 2023
@aki-k
Copy link

aki-k commented Jun 16, 2023

Found a fix for this problem: #10138 (comment)

@zhl-HFUT
Copy link

@LWJerri You could have left this issue open so that Microsoft could've also commented about the problem :)

You helped me a lot today! I can see you under this relevant question, and it feels like you have a good understanding of WSL2. I'm really curious how you discovered the command "dbus-launch true".

@aki-k
Copy link

aki-k commented Oct 17, 2023

I'm really curious how you discovered the command "dbus-launch true".

I don't really remember how I found it, but it had something to do with other peoples' solutions to start a process in WSL 2 to keep the instance alive.

@aki-k
Copy link

aki-k commented Oct 18, 2023

I think what's happening is that when you run "dbus-launch true" in WSL 2 instance, it starts the user dbus-daemon

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants