-
Ran
sudo visudo
. Add this line:ALL ALL= NOPASSWD: /usr/local/etc/start_services.sh
-
Create file
/usr/local/etc/start_services.sh
touch /usr/local/etc/start_services.sh chmod go-rwx /usr/local/etc/start_services.sh chown root:root /usr/local/etc/start_services.sh
-
In the file, run the services needed:
#!/usr/bin/env sh service cron start
-
In
~/.zprofile
(or other profile scripts of your favourite shell). Add these lines:service cron status >/dev/null 2>&1 || { echo 'Services have not started. Starting services now' sudo /usr/local/etc/start_services.sh }
-
Press Window+R, run
shell:startup
-
Create a file named
start-wsl.cmd
. Add these lines:@echo off echo Starting WSL... wsl -e echo "WSL Started" echo Starting services... C:\Windows\System32\bash.exe -c "sudo /usr/local/etc/start_services.sh"
Created
October 29, 2021 07:14
-
-
Save hktonylee/071134e8873382c1645fa45de53abc8c to your computer and use it in GitHub Desktop.
How to auto-start WSL during Windows startup, and run services (e.g. cron) in WSL2?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment