Note: I'm cross posting this from my blog to dip my toe into dev.to
More and more developers are finding out that the Windows Subsystem for Linux ...
For further actions, you may consider blocking this person and/or reporting abuse
This will not necessarily work when you are runnning multiple WSL distros in parallel. You can resolve this by changing the command line in the task schedulder. In the following example I assume you want to run postgresql in Debian, which is not your primary/default WSL distro:
Instead of 'C:\Windows\System32\bash.exe' write 'wsl'
Instead of '-c "sudo ~./local/bin/start_postgresql.sh"' write '-d debian -e sudo /home/calvin/.local/bin/start_postgresql.sh".
(Yes, I had trouble with the ~ shortcut for the home directory, no idea why.)
if the command is sudo, anything after that is already run as root, so the ~ would mean /root and not /home/calvin
So, I started with your suggestion, but quickly realized most services are already scripts in /etc/init.d, and you usually manage these things with users. For example, for docker, I created a
/etc/sudoers.d/docker.sudoers
file, with the following:I think I'm also going to see if I can get a feature request endoresed for a
[autostart]
config section for the/etc/wsl.conf
file where you could just list services to autostart like so:It's nice to bring Unix tooling into Windows, but, as a Linux and Mac user, I'm curious as to what Windows brings to the table. My brief experiences with Windows post-XP were mostly frustrating. The UI for managing the machine is confusing and crude, downloading updates is slow and either slows down the machine or locks it down until finished.
I dunno, man. I'm not trying to sell you on Windows. I'm trying to help out people who already decided to use it. :-)
There are some of us that are forced to use Windows because of our employers, IT and the MS Apps that they require. This is easier than trying to get Linux working in a MS environment and using Open Source apps and WINE to satisfy the requirements.
if u are a full stack dev, or freelance solutions provider, its nice to have adobe products at your fingertips without rebooting while in programming mode
I would like to give my 20 cents and suggest to use just one single script (/home/youruser/autoexec.sh) to call ALL services wanted thru Task Scheduller.
And not just for postgres.
But man... you save the day!!
Thanks a lot!!!!!
I'm afraid it didn't work for me...
I need to run the same command:
service postgresql start
and it just isn't started (it runs fine as root/sudo). File permissions for the script are good wrxwrxwrx. I do believe shell starts and the script is being run.I have Windows build 17692. I must be missing something...
Great post, I appreciate it!
I'll keep trying. Cheers.
UPDATE: IT IS WORKING!!!!!!!!!!!
Yay!!!
I had been rebooting the windows machine by "restart"... This morning when I booted it from shutdown state, the Postgres server was running. And this is from the script and task scheduler you explained.
Thanks again.
it worked for me, thanks!
However, I am curious why not put 'sudo' in bash script, but put it in the task scheduler's command. If you put it in the bash script, you could avoid typing sudo when you used it from the console.
I would not do what is suggested here.
What you have done is allowed passwordless execution of a user-editable shell script haven't you?
If I wanted to execute arbitrary code under sudo I would simply edit that shell script and then use the permission to execute that shell script as a sudo user.
You need to make sure that whatever script you are allowing anyone to call without providing the SUDO password (as the sudo user) is uneditable.
Otherwise there is NO advantage to trying to avoid allowing passwordless SUDO.
I'm not a nix guru, so I don't have a working solution for others to read here, but the specific advice given here isn't great, I'd suggest looking for a different script that is owned by the sudoers that cannot be edited by a non-sudo'er to allow passwordless sudo'ers to execute to achieve the same functionality.
I was also late to realize that Apache and MySQL was not started automatically in WSL land.
Although this method shows an awkward flash of bash window during startup. But hey, at least it works. Thx for the tip!
I just start the postgresql server in the script and add that script to
~/.bashrc
I've tried very hard to make it work with Redis but it didn't work!
I used this official Redis article to install Redis redislabs.com/blog/redis-on-window...
Any help?
Thanks! You got my engine started on this. Here's what I came up with.
satalink.blogspot.com/2019/05/wind...
Nice. As a non-Windows user who is intrigued by WSL I found this a useful look into where Windows devs heads are at with this stuff. Have you encountered any major frustrations yet?
Oh for sure! It has some filesystem performance issues in the IO layer between the Linux kernel interface and the Windows storage system. It doesn't affect most things but operations on lots of tiny files (like a Git repo!) can be a big problem. The team is working on that, I understand.
Thanks @ironfroggy ! This helped me as well.
Perfect. Just used this to start php7.3-fpm, nginx and mysql. Works well! Thank you!