-
Notifications
You must be signed in to change notification settings - Fork 826
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
The WSL instance still shuts down automatically when all WSL terminals are closed, after waiting for a while. #9968
Comments
This is intended, see #8654 (comment). |
If you setup systemd in WSL 2 with https://github.com/DamionGans/ubuntu-wsl2-systemd-script , WSL 2 won't stop if you close all the shells/terminals. Please note that that repository is not updated any more, but it still works. By default it sets systemd to use basic.target, but you can change it in the two files enter-systemd-namespace and start-systemd-namespace (one change in each file). For WSL 2 distro Ubuntu-22.04 there's also a need to patch enter-systemd-namespace with the patch from DamionGans/ubuntu-wsl2-systemd-script#36 (comment) (the change goes to the end of enter-systemd-namespace). |
Just provide a workaround. If you allow WSL2 distro able to execute Windows program, you can try this workaround #8854 (comment). |
Thank you for your reply. I will try it. |
Thanks for your reply. |
Is that a ChatGPT hallucination? I don't see that as a valid configuration option in the doc or the recent release notes. I'll propose two easy solutions:
|
Found a fix for this problem: #10138 (comment) |
thanks you for you reply, but i exec the command has some errors wsl --exec dbus-launch true erros:
|
@ImmortalD Ok could be a difference in the WSL 2 version. I installed 1.2.5 yesterday. |
My Windows automatically updates itself. We have the same version. wsl -v
|
@ImmortalD How about the distro version? I use Ubuntu-22.04 |
I encountered the same problem and it was resolved by turning off systemd
|
Try if this fixes it: #10138 (comment) |
These are all the apt-get commands I've run in the WSL 2 Ubuntu-22.04 instance
Edit: for some reason I need to use "dbus-launch mate-terminal" to start it Edit 2: there's some weird bug with something to do with wayland and mate-terminal. If I just launch it with "dbus-launch mate-terminal", when switching between another Windows program and mate-terminal makes mate-terminal shrink one column at a time. To launch it in X11 mode, use "dbus-launch mate-terminal --display=:0" and the problem doesn't manifest itself any more. |
I solved in this way: then I put this command inside bat file on startup folder located in: @echo off and it always be running at every reboot. |
By customizing the script you can keep WSL2 running in the background, if there is a more elegant way, click me First, create a script file keep_wsl_running #!/bin/bash
while true;
do
sleep 10;
done; Then run the script when .bash_profile or .zshrc starts # keep wsl running background
ps -ef | grep keep_wsl_running | grep -v grep >> /dev/null
if [ $? -ne 0 ]; then
nohup ~/Private/bin/keep_wsl_running >> /dev/null 2>&1 &
fi Running the nginx container with docker in wsl, closing all Terminal windows, and being able to access nginx through a browser no matter how long it takes, this one met my expectations |
@srikker Start the WSL 2 instance like this, and it'll not shutdown automatically:
|
This method requires manual startup at the command line, which increases the operation cost. |
@srikker You can create a new Windows Terminal profile and define this batch file as its "Command line":
|
Works just fine for me with systemd enabled, kinda the whole reason I want WSL to persist is so I can enable startup services (ssh) with systemd from windows land. |
@hemenge133 If you start up the WSL 2 instance like this, it will continue running even if you close all the shells/terminals:
|
any official update for this? |
@berryscone What do you expect Microsoft to do? They've designed WSL 2 so that the instance will automatically shutdown after you've closed the shells that keep it running. |
@aki-k I expect for them to provide an option to disable this behavior. Are you a person in charge of WSL in MS? |
@berryscone No, I don't work for Microsoft. Now that Microsoft and Canonical created WSL, they should make it work as well as they can without artificial limitations. Here's the command you can use so that the WSL 2 instance doesn't shutdown automatically:
|
I stumbled accross this and related issues being convinced, that this wasn't an issue for me over the past year(s). In the beginning my explorer didn't show the Linux location and some older programs I was using did not work with UNC paths. There I connected mit default wsl instance root's UNC as a network drive and set it to reconnect automatically. And it works again like a charm. Shortly after windows reconnects, my instance boots up and all systemd services are active in the background. I post this just in case it might help some of you who are not satisfied with the dbus-launch solution. |
@parapilot I wrote about the automatic WSL 2 start at system startup for both Windows service method and for Task Scheduler method here: |
How long do developers need to endure this type of nonsense? |
@imsir0vic The fix for the WSL 2 instance auto-shutdown is to start it like this:
|
Have you even tested this?? PS C:\Users\pedro> wsl -d Debian
nostromo% which dbus-launch
dbus-launch not found
nostromo% |
@pedrohgmacedo I have "even" tested it. The option says Ubuntu, not Debian, so install it if you don't have dbus-launch. |
What in the world is happening? I'm providing help here and get thumbs down? |
Cmon Microsoft, this is a huge PITA, but a simple thing to implement. Please add a setting to completely disable the shutdown and/or configure the idle timeout. |
@kacprawcze Here's the solution: C:\>wsl.exe --distribution Ubuntu-22.04 --exec dbus-launch true & wsl.exe --distribution Ubuntu-22.04 |
Thank you, but a lot of people posted that already. And that's not a solution, that's a nasty workaround. |
@kacprawcze So instead of starting WSL 2 like that, solving the problem, you instead want to wait for Microsoft to fix it what they are not interested in doing? "Nasty workaround" lol |
I found a solution with Install docker destktop, It't enable |
Why is this a nasty workaround? just add |
To all the haters; it should be obvious by now to everyone that Microsoft has no plan to fix this issue. |
a workaround I found is starting a |
It's weird because, If I execute the command After some testing I found something else; Apparently If I close the terminal by clicking on the X button it's when WSL will shutdown, but if I execute |
Windows Version
Microsoft Windows [版本 10.0.22621.1555]
WSL Version
WSL 版本: 1.2.0.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.22621.1555
Are you using WSL 1 or WSL 2?
Kernel Version
默认分发: rocky9 默认版本: 2
Distro Version
No response
Other Software
docker --version # Docker version 20.10.21, build baeda1f
Repro Steps
I have already configured to prevent automatic shutdown, the configuration is as follows:
.wslconfig
[root@DESKTOP-2U5HSUB ~]# cat /etc/wsl.conf
Expected Behavior
The WSL instance keeps running even after closing all terminals.
Actual Behavior
The WSL instance automatically shuts down after waiting for a while after closing all terminals.
Diagnostic Logs
DebugConsole logs the following when WSL is closed.
The text was updated successfully, but these errors were encountered: