-
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
How to make wsl2 alive in the background #10138
Comments
@amunv WT has a headless feature (microsoft/terminal#14944) that might keep your WSL instance running. |
I don't understand it a bit, should I add "allowHeadless": true in setting.json |
@amunv You can make it stay running with this setup: #10157 (comment) |
Thank you for reporting this @amunv. You can force WSL2 to keep running with:
in %userprofile%/.wslconfig |
I'm not sure why this is not documented at https://learn.microsoft.com/en-us/windows/wsl/wsl-config It just says
|
This is not what I need. About ten seconds after closing the terminal, wsl enters the suspended state. At this time, the docker application cannot be used normally, and the system memory usage is reduced. The "vmIdleTimeout" option controls the survival time of vmmemwsl after wsl is suspended. During this time, when WT is turned on, wsl will run normally. I don't need this suspend state and control the time after suspend. What I need is that wsl suspend after about ten seconds, disable this suspend. |
Yes, that's exactly what |
@OneBlue Your solution does not work. I put
into C:\Users\aki\.wslconfig and restarted WSL 2 VM. Then I installed apache2 in WSL 2 VM
I can see in "ss -tulpan | grep apache2" that it's listening on port 80. Then I load http://localhost/ on Windows host side Firefox and the Apache2 Ubuntu Default Page opens. I exit from WSL 2 VM with "exit". I have this loop running in another CMD prompt
It lists the processes matching "vm" and "wsl". When I exit WSL 2 VM, the 2 wslhost.exe processes end after a short while. The Apache2 Ubuntu Default Page on the Windows host side Firefox stops responding at the same time. |
@aki-k |
means I exited the WSL 2 VM and ran wsl --shutdown in CMD prompt. Do I also need to restart lxssmanager? |
After "exit" -> 2 wslhost.exe processes stop after a short while -> "bash" -> I can use "ps auxwwf | grep apache2" to see the process start-up time and they just started up. So the WSL 2 instance also started up again. |
I actually now found a command that starts WSL 2 VM, exits, and WSL 2 VM and instance are left running:
|
This command is very useful, but I have another problem about WT.The command line of Profiles is run by cmd in windows terminal.The exec parameter cannot be recognized normally in cmd, but it can be recognized in powershell.Do you have an idea to change the command line to pwsh, or let cmd recognize "-e"? |
@amunv
I don't use Windows Terminal, just CMD prompt (with clink) and it works in it. |
Sorry,I just misunderstood this command, I thought this would start the wsl instance. |
@amunv Yes, it starts the WSL 2 VM and the WSL 2 instance. |
@amunv i.e.
|
Savior for real. In most cases the timeout = -1 or dbus-launch true should work. for context, if anyone cares ,I am trying to run a ssh-server to login into WSL2 from my macbook. This was the final piece of the puzzle <3. Thanks much. |
@aki-k This works for me, the wsl stays running. But After a reboot do you need to put the command in again? After I rebooted it said it was running but after a minute it said it stopped. |
For Windows 10 (because the
The |
Running Windows 11 Pro, and my
However, when I close the WSL Ubuntu window my systemd services stop. Is there a way to continue to have them run when the Ubuntu window is closed? |
@nodesocket The solution (until Microsoft fixes it) is to start WSL 2 like this: C:\>wsl.exe --distribution Ubuntu-22.04 --exec dbus-launch true & wsl.exe --distribution Ubuntu-22.04 |
Thanks for the reply. I'm a macOS and Linux guy, is there a way to make the above a shortcut? |
@nodesocket Well try this :)
Put the above in start-wsl-2.bat in your %PATH% (CMD prompt) / $env:PATH (Powershell). |
@nodesocket Here's a better solution that doesn't open an extra CMD prompt/console window:
^- start-wsl-2.vbs |
I have added there lines to .bashrc:
|
I just wrote a simple systemd service keeping WSL instance alive: keepwsl |
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 |
Wsl2 will automatically shut down when the terminal is closed.I need it alive in the background.
Is there such a function in the configuration file, so that wsl2 can only be closed manually by running wsl --shutdown. If not, would you consider adding this feature.
The text was updated successfully, but these errors were encountered: