You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it seems that Ubuntu used upstart and now uses systemd for service management.
I installed mpd and want this service to auto-start. Installation seem to created valid auto start service script as /lib/systemd/system/mpd.service but service does not start unless I manually start with sudo service mpd start.
So I wanted to ask how to auto start service generally in WSL?
Reacted by Yaron Meiner, Christian Scholz, Arash, Matthias Küch, Yukai Huang, Bao Bo, Travis Plunk, Will, Nguyễn Đức Tuấn Anh, Alex Kmn and 8 more
Background tasks are currently not supported on WSL. One way to accomplish this right now would be to use the "bash.exe -c " to start whatever you want. If you want that to auto start post Windows boot, you can hook that command to the Windows startup.
Reacted by Konstantinos Mattheakis, Daniel Saldivar-Salas, Tim Smith, Escape0707 and shimou
Thanks Sunil Muthuswamy (@sunilmut). I'd also like to add that any daemons that you run will be terminated when the last bash.exe goes away so you'll have to leave one bash.exe running.
Is there any more elegant way in the meantime that is more similar to systemd/upstart?
Reacted by Rahil Wazir, Christian Scholz, Raphael Tweitmann, Lorenzo Ferri, Andrew M., Gaston Cababie, Artem Russakovskii, Hicham Boushaba, Arash, Werner and 7 more
Andrew Grosser (@dioptre) - Background tasks, daemons are now supported starting Insider build 17046. See the blog for more details. But, auto start of services is still not available. More detailed discussion on that at #834, #612
Ben Hillis (@benhillis)'s remark is no longer true.
I can successfully exit wsl while I run shellinabox in a tmux server in wsl, without my shellinabox session being interrupted.
Ben Hillis (@benhillis) We can start the cron service manually, and it will run as long as the terminal is open, but when we reboot Windows it doesn't start automatically, nor after opening a Bash window.
Correct me if i'm wrong just running -c with a command will not be enough, you need to exec bash at the end to get the window to stay open.
You can either do this: bash.exe -c 'bash /path/to/file.sh; bash'
or add $SHELL at the end of the script.
Here's a minor improvement: in bash.exe -c 'bash /path/to/file.sh; bash', the last bash will start bash as a child of the current bash process. Using exec will replace the current process:
bash.exe -c 'bash /path/to/file.sh; exec bash -i'
The final -i may be omitted in most situations.
Use pstree to show the current process with its ancestors.
Now my solution is adding such like command to ~/.bashrc, service start tor
Works well.
In this case, for every instance you'll have extra line of command that potentially cause a delay (might not quite noticeable but definitely not elegant) for example when opening a new tab.
Activity
sunilmut commentedon Jun 15, 2016
Background tasks are currently not supported on WSL. One way to accomplish this right now would be to use the "bash.exe -c " to start whatever you want. If you want that to auto start post Windows boot, you can hook that command to the Windows startup.
benhillis commentedon Jun 15, 2016
Thanks Sunil Muthuswamy (@sunilmut). I'd also like to add that any daemons that you run will be terminated when the last bash.exe goes away so you'll have to leave one bash.exe running.
ymeiner commentedon Aug 12, 2016
Correct me if i'm wrong just running -c with a command will not be enough, you need to exec bash at the end to get the window to stay open.
You can either do this:
bash.exe -c 'bash /path/to/file.sh; bash'or add $SHELL at the end of the script.
ZuSe commentedon Apr 10, 2017
Is there any more elegant way in the meantime that is more similar to systemd/upstart?
skywind3000 commentedon Jul 26, 2017
It is 2017 now, we still have this problem.
the background service is the last thing stopping me to swith from cygwin to wsl.
Has it been planned in the feature release ?
Any roadmaps ??
dioptre commentedon Jan 10, 2018
This question is not answered here. Any progress on this?
sunilmut commentedon Jan 11, 2018
Andrew Grosser (@dioptre) - Background tasks, daemons are now supported starting Insider build 17046. See the blog for more details. But, auto start of services is still not available. More detailed discussion on that at #834, #612
troytse commentedon Jul 16, 2018
Hi guys, I made a script to support starting the WSL services on Windows start.
WSL-Autostart
mathieucaroff commentedon Sep 1, 2018
Ben Hillis (@benhillis)'s remark is no longer true.
I can successfully exit wsl while I run shellinabox in a tmux server in wsl, without my shellinabox session being interrupted.
benhillis commentedon Sep 1, 2018
Yeah that was 2+ years ago. We have added support for background tasks in the meantime.
Justsoos commentedon Dec 8, 2018
Ben Hillis (@benhillis) really? now I run WSL Ubuntu 18.04.1
and the services, some with
+, but how to set up the-service as autorun ?mnpenner commentedon Jan 10, 2019
Ben Hillis (@benhillis) We can start the cron service manually, and it will run as long as the terminal is open, but when we reboot Windows it doesn't start automatically, nor after opening a Bash window.
Justsoos commentedon Jan 18, 2019
Now my solution is adding such like command to ~/.bashrc,
service start torWorks well.
mathieucaroff commentedon Jan 18, 2019
Yaron Meiner (@ymeiner)
Here's a minor improvement: in
bash.exe -c 'bash /path/to/file.sh; bash', the lastbashwill start bash as a child of the current bash process. Usingexecwill replace the current process:bash.exe -c 'bash /path/to/file.sh; exec bash -i'The final
-imay be omitted in most situations.Use
pstreeto show the current process with its ancestors.lenowng commentedon Nov 30, 2019
In this case, for every instance you'll have extra line of command that potentially cause a delay (might not quite noticeable but definitely not elegant) for example when opening a new tab.
javierguzman commentedon Mar 15, 2021
Any better way to do this in 2021? Thank you in advance and regards