I added these lines in my WSL settings files
C:\Users\reynadan\.wslconfig
:
[boot]
command=bash /home/reynadan/scripts/startup.sh
/etc/wsl.conf
:
[boot]
command=bash /home/reynadan/scripts/startup.sh
/home/reynadan/scripts/startup.sh
#!/bin/bash
# Run wsl-vpnkit if not already connected or running
currentlyRunningWsl=$(wsl.exe -l --running | iconv -f UTF16 -t UTF8 | grep wsl-vpnkit | wc -l)
if [[ $currentlyRunningWsl -eq 0 ]]; then
wsl.exe -d wsl-vpnkit service wsl-vpnkit start
fi
# Start Docker daemon automatically when logging in if not running.
RUNNING=`ps aux | grep dockerd | grep -v grep`
if [ -z "$RUNNING" ]; then
sudo dockerd > /dev/null 2>&1 &
disown
fi
NOW=$(date)
echo WSL booted at $(/bin/date +'%Y-%m-%d %H:%M:%S') >> /home/reynadan/wslBootHistory.txt
echo 'startup lanched'
I closed with wsl --shutdown
and waited more than 8 seconds before running it again, but /home/reynadan/wslBootHistory.txt
is still empty and docker is not running.
How do I make sure WSL runs my script on startup?
[boot]
is only available on those OS. – Michaels[boot].command
is the/etc/wsl.conf
, since you can have a separate startup process for multiple distributions.%userprofile%\.wslconfig
, on the other hand, is shared among all WSL distributions --[boot].command
doesn't apply there. – Warfare