Do you want to make WSL (Windows Subsystem for Linux) automatically start all your Nginx, MySQL, apache2... etc. services at startup? It is a common requirement for a developer.
With WSL, Microsoft enables you to run Linux distros directly on Windows 10 without using any Virtual machine platforms(VMWare, VirtualBox..). Once you setup your development environment in Linux distros, the next step is auto-start services on Windows 10 reboot. This post will explain the steps to do that.
I am using Ubuntu 18.04 for this post.
1. Open Ubuntu terminal and create a startup file at /etc/init-wsl:
#!/bin/shecho initializing services
service apache2 start
service mysql start
Add all Ubuntu commands which you want to execute on startup.
2. Make the script executable, by running the following command:
chmod +x /etc/init-wsl
3. Open Task Scheduler in Windows 10
On the left, click "Task Scheduler Library" option and then on the right, click "Create Task" to create a new task.
- In General Tab, Enter Name: "WSL Startup", Description and Select "Run whether user is logged on or not" & "Run with highest privileges" options.
- In Trigger Tab, Click New ... > Begin the task: At startup > OK
- In Actions Tab, Click New ... > Action: Start a program
Program/script: wsladd arguments: -d Ubuntu-18.04 -u root /etc/init-wsl
Replace Ubuntu-18.04 to your distros
Click OK
- In Conditions Tab, Select options as per your preferences, I prefer to uncheck AC power related options
- Keep Settings tab with default options.
- Click OK
Now reboot Windows 10 and check the services in Ubuntu. You will get all the services started and can work on the related web application directly.
Enjoy Windows!!