-
Notifications
You must be signed in to change notification settings - Fork 829
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
Services do not start when Windows starts (nginx, php-fpm, mysql) #834
Comments
Hi @deyvisonrocha -- are you able to run a command to start each of these services manually? If so: There are instructions here on how to start sshd when your computer starts. You could probably do the same thing for each of the three services that you listed, but swap the command to start sshd with the command that you are using to start each of those processes. |
Sounds very much like #612, and the Devs seem to think it needs a resolution of this Uservoice issue. It's possible to get things running as services, but it is not exactly user friendly. I'm still having trouble getting services to start after the OS boots but before I log in. One could probably make a folder somewhere, populate it with scripts that need to run as "services", and use |
@aseering It did not work for me. =/ |
@deyvisonrocha -- hm... Do you have any errors in either the Windows Task Scheduler or the logs for the programs that you were trying to start? There was also recently a mention on some ticket (I forget which?) that recent versions of WSL require that the Windows startup script used here to also restart the lxssmanager? Maybe someone here will have seen that thread and can comment. |
To give a little bit of context why our service story is currently a little funny. We create a WSL "instance" when an NT client launches a Linux binary. Other NT processes launching Linux binaries will create them within the same instance. When the last NT client goes away the instance is terminated meaning all Linux applications running will exit. This way you're only running Linux binaries when you need them. Services represent an interesting design problem. To support running them natively we'd have to boot an entire (potentially a subset) Ubuntu OS including the Ubuntu's init and daemons. These would be running at all times and you'd essentially be running two full operating systems with one kernel. We're definitely looking at ways to support running Linux services better in the future. Potentially some kind of "keep alive" to keep an instance running even after an NT client has gone away. |
@benhillis I even came up with a name for this "ubuntu as a linux service host process" idea, "lxsssvchost.exe" with obvious allusions to the Win32 service host process. |
@benhillis - As long as the -c "scriptname" option works with bash.exe, if you put a "while true" loop at the end of the script (with some sleeping to keep load reasonable?), it will run pretty much forever. Or one can run a daemon in the "foreground" to keep the environment open forever. The technique for launching it from Task Scheduler without a console window cluttering the desktop means we are almost there (see the instructions at Adam's forum, and other places, for the technique). It's not a full upstart/init, but it is definitely running without a console window open. Keeping the script running forever or the daemon running in the foreground means the environment doesn't close. So it clearly functions as a service, even if we have to go through extra steps to make it work. So having the devs operating on the assumption that the only thing that can possibly work is the full console while the user is logged in -- that seems to be a bit more restriction than needed or helpful. |
@rodrymbo Personally the -c "scriptname" in a while loop sounds worse than just keeping a bash.exe window open. What I'm going to suggest is simply a workaround (not a final solution) but I feel like I can share it since this is a developer feature :) If that part really bothers you, you could always write a small NT app that uses the CreateProcess api to launch bash.exe hidden (and then sleep forever). http://stackoverflow.com/questions/780465/winapi-createprocess-but-hide-the-process-window That being said, we do have an undocumented com interface that some people have already started poking around at (#790) that could be used to similar effect. Eventually I suspect we will document the interface, but later when things are less in flux. |
@benhillis -- well, the while loop is in the bash script, not a CMD script. So it basically keeps the bash script running forever, like a daemon running in the foreground. The point is that technique, run from Task Scheduler, means the console is not running. The process running forever inside bash.exe keeps it from exiting. So while CreateProcess would do it, TaskScheduler does also, and doesn't require me to compile anything. :P A while loop in Bash (or sleeping forever) is a bit inelegant. If you need something simpler, think of running The reason something has to run or sleep forever in the foreground, is that, since it is a script, it is not running interactively. As soon as the last thing finishes, the script -- and bash -- exits, so anything launched into the background is lost, by WSL design. So you can have a script launch things into the background or as daemons, but unless it sleeps or does something in a loop, or launches the last process to run forever in the foreground, as soon as the script finishes, bash and all the stuff it so carefully started running, will close (currently). |
Bash scripts can sleep forever too :-) |
Sleep -1 for the win? |
Nope! No sleep for us.
|
Try not to lose too much sleep over the 'interesting design problem' of having two operating systems running. I don't know about everyone else, but according to my Resource Monitor, I've got several operating sized systems running already. My biggest operating system, by far, is called So at this point, I'm pretty comfortable with |
@therealkenc -- you should start emacs, add another operating system :-) (says /me as an emacs user) |
@rodrymbo et al -- I've summarized the http://wsl-forum.qztc.io/viewtopic.php?f=6&t=10 Definitely a workaround. But it might help for now. |
Joking aside, I hope this is solved by just putting the WSL 'instance' in the tray, just like Chrome or OneDrive. Defender is only offensive because it has no 'exit' menu item. That's also where |
A pretty little tray icon would be nice, but a higher priority for me would be getting a few daemons going at boot (before the user logs in). Being able to start sshd and cron and maybe a web browser or database would make things much more useful. I suppose some might want to try to get a full Ubuntu system going at boot, but I'd be happy with just a few things. A bash console has almost everything we need, once a few processes are running in the background, like syslog and cron (assuming network interfaces and other gotchas are fixed). |
The icon isn't the point. Having If people want their |
@therealkenc - The normal linux paradigm would have bash (or probably login/getty) open a terminal window, do stuff, and then close the window again when bash exits. And if all of the Ubuntu daemons and services were left running when that bash console closes, I'm sure there'd be too many complaints to Microsoft. So it seems to me that having things run in the background or as daemons or services should be reserved for those who tell WSL that's what they want. But once we have that sort of environment running, I'd say it should stay running until the user tells it to stop. And once that environment is running, there'd be no need for reference counting, just the usual process management, commands inside the bash environment (like ps and kill, perhaps shutdown). Having It looks like your idea of I think I would support it defaulting to shutting down when the console closes, for normal users, as long as we can easily get to a more complete environment (syslog, cron, etc) that starts when the user logs in and potentially when the PC boots. It looks like the pieces are there and working, it's just a matter of the WSL devs putting together the best way to do it and finding time to implement it. |
The 'normal Linux paradigm' doesn't even know what a window is. Never heard of them. Bash doesn't know what a window is either. On Linux, the X11 service from X.org knows what a window means. As I said, none of the Ubuntu services you are talking about need to be running. None of them. They can, of course. But they don't need to. Microsoft seems to be perfectly okay with 33MB worth |
We are pretty much there, now, except Microsoft seems to be saying that the minimum number of things running (besides init) should be one (bash) while the rest of us are saying we'd like the option to run 0 (or at least 0 bash) without it shutting down. I doubt it would run with 0 very often, but that's a way to generalize, sure. init in WSL doesn't seem very huge or use much resource (in real time). It probably has a virtual size that is much larger, but it's not using it all the time. I can't imagine Microsoft thinks having init running all the time will bog down a machine being used by a developer. (It might on a phone, but I wasn't contemplating setting up a cheap underpowered phone that way.) So it is just a matter of convincing them it's what we want. Microsoft wants us to tell them what we want it to do. Almost every use case for me involves some daemon or service or something running in the background. Programs I run (not all) expect to be logging to a syslog daemon. Jobs need to run when I am not sitting there to start them, and they want to log to syslog too. And so forth. I expect to be able to have some things running all the time. Having everything in /etc/init.d running probably wouldn't be that huge a deal, but I don't need more than a few, or even the same ones all the time. I probably shouldn't call them "windows", those rectangular things with the black background and white text (typically). Regardless of what I call them, I think of them as terminal emulators, like the physical terminals I started out with (after playing with actual teletype-and-paper style machines). But yet they are rectangular, and all those other rectangular things on the desktop are called windows, so there you have it. Bash does of course know whether it is talking to a terminal (interactively) versus running in the background, and what kind of terminal it is controlling. Perhaps we can get away with a relaxed use of "window"? I think I like the terminal paradigm in linux better than the cmd/conhost console in Wndows. Being required to have conhost hanging around seems somewhat backward. But what I've seen is conhosts closing when they aren't needed. The only conhosts running on my machine are associated with some process that thinks it needs to run in a console (even when it isn't visible), and the conhost closes when that process closes. Maybe there are some that don't close, but I've not seen them. So probably not the best example of things running in the background all the time without closing. |
The physical VT100 terminals you started out with talked to a service that ran all the time without closing. It's called getty.
|
Instead of looping or sleeping just add "bash" to the end of the shell script. Here are my scripts for apache and mysql to run on startup. VBS file (runs on startup)
autostart.sh file
and in /etc/sudoers
If I need to kill it all I can find the bash process in Task Manager and kill that. |
People can argue back and forward about the best way to do this but at the end of the day as a developer all I want is when services like nginx, PHP-FPM, etc are told to start at start-up I can expect them to be running next time I login to start working on something |
@AaronMcHale parts of this feature are already implemented. It's coming along, so please be patient. |
@AaronMcHale - Exapanding on @fpqc comment, for example, you can see this blog post for support for background tasks. So, while, startup tasks are still not supported, workarounds are possible now. |
@sunilmut Is the old WSL blog abandoned? If so, you should put a post on there pointing people to the commandline blog. Or is that blog going to be reserved exclusively for technical details of the WSL internals? |
No, the old blog is for more technical topics. |
I actually like the idea of 2 full operating systems with one kernel. Just look at the history of the kernel. "Strictly speaking, an operating system (and thus, a kernel) is not required to run a computer. Programs can be directly loaded and executed on the "bare metal" machine, provided that the authors of those programs are willing to work without any hardware abstraction or operating system support." This being the case, there's no reason why we can't make it so services start from Linux upon Windows boot. Just provide the core that allows Debian, RPM, Gentoo, etc. -based systems to run upon boot once you install a distro. Work has already been done to make WSL agnostic to a particular distro. Autostarting services really is a necessity for devs (who are the target audience right now) but also for enterprise scenarios as well. The overall goal of WSL shouldn't just be about devs, it should be about supporting all customers who could potentially utilize it. This one issue would be one of those things to help reach that goal. |
2 years passed, does MS have ability to solve this simple issue? |
Wanted to install Redis on windows today and found the documentation to refer to run it under WSL. |
Ran course. LZ for systemd #994. |
Hello,
Everyday I need start the services on Bash (nginx, php-fpm, mysql). Is there any way to do it is automatic?
Build number: 14393.10
The text was updated successfully, but these errors were encountered: