Fork me on GitHub

WSL开机启动mysql等服务


命运是什么?命是弱者借口,运乃强者谦词

WIN10设置

进入windows开机启动目录,先在运行>命令(win+r)中输入shell:startup打开启动文件夹
新建vbs文件start-wsl.vbs:

1
2
3
4
5
Set ws = WScript.CreateObject("WScript.Shell")
cmd = "C:\Windows\System32\bash.exe -c ""bash /home/init.sh"""
ws.Run cmd, 0, false
Set ws = Nothing
WScript.quit

WSL设置

在WSL系统里创建/home/init.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

# 自动输入sudo密码
sudo -S service ssh start << EOF
123456
EOF

sudo bt start
sudo service ssh --full-restart
sudo service nginx restart
sudo service mysqld restart
sudo service redis restart
sudo service php-fpm-73 restart
sudo service cron start
sudo supervisord
sudo supervisorctl start all
# 运行bash.exe不退出
while true
do
sleep 600
done

赋予执行权限

1
chmod +x init.sh

https://tech1024.com/original/3006
https://www.jianshu.com/p/0a102c4bb3a2

请我喝一个苹果味的美年达吧,谢谢!