WSL自动启动 service

问题

WSL 无法自启动service

image-20210908181459004

解决方式

1. 新建bat脚本

例如需要自启动 sshdocker 服务,新建一个 wsl_startup.bat如下

1
2
wsl -d Ubuntu -u root -e sudo service ssh start
wsl -d Ubuntu -u root -e sudo service docker start

这里的 -d 用于指定不同的WSL,可在 CMD 通过 wsl -l 查询到

image-20210908182257147

2. 复制脚本到windows自动目录

运行中输入 shell:startup

image-20210908181836285

复制刚才新建的脚本到此目录

image-20210908182008660

3. 重启系统