Windows Subsystem for Linux (short WSL) is a binary executable file to run Linux (ELF format) is on the Windows 10 natively compatible layer. After than in the Windows virtual machine to run Linux, WSL much more convenient, but each time you exit wsl, the open services, such as: ssh, mysql, supervisor and other services is impossible, have to manually restart each time open , very inconvenient, This paper focuses on issues encountered in my work and practical to record.
Internet also wrote many articles on how to open automatically when the window started service instead of manually entering the wsl open, but still can not solve the problem since the start of the boot, after some exploration and toss, and finally solve the problem, this share issue to everyone I meet, ado.
1. First create a shell script to save the command you want to turn services:
#!/bin/sh service ssh $1 redis-server /etc/redis/6379conf service supervisor $1
Note: Your order must be on! ! !
Then save
sudo nano /etc/init.wsl
Where each row is the command you want to open a corresponding service, $ 1 for the implementation of the first parameter of the received file, the file name $ 0 for the execution, such as:
sudo /etc/init.wsl start, which receives $ 0 as /etc/init.wsl,$1 received as start, related presentations: https://blog.csdn.net/qq_30137611/article/details/77092524
2. Add execute permissions
sudo chmod +x /etc/init.wsl
So that the file can be executed, you can call this file to open inside the service,
sudo /etc/init.wsl start
3. Edit the sudoers, avoid password
sudo vim / etc / sudoers, add the last line
%sudo ALL=NOPASSWD: /etc/init.wsl
Such start time would not have to enter a password, and boot from the start when there is no password to prevent failure from the start.
4. Return windows interface to create a script startservice.vbs
According to the online tutorial, says:
Set ws = WScript.CreateObject("WScript.Shell") ws.run "C:\Windows\System32\bash.exe",0 ws.run "C:\Windows\System32\bash.exe -c 'sudo /etc/init.wsl start'",0
Save, and then reboot the system, / etc / init.wsl inside open service script into effect, ok.