Steps to Start Automatically When WSL Starts
- Edit
.bashrc
or.profile
: Open the.bashrc
file in your home directory:nano ~/.bashrc
- Add the Start Command:
Add the following lines at the end of the file:
# Start Stable Diffusion silently if [ -z "$(pgrep -f 'webui.sh')" ]; then cd /stablediff/stable-diffusion-webui || exit ./webui.sh --listen --api > /dev/null 2>&1 & fi
- The
pgrep -f 'webui.sh'
ensures it doesn’t start multiple instances if it's already running.
- The
- Save and Exit:
Save the file (
Ctrl + O
, thenEnter
) and exit (Ctrl + X
). - Apply Changes:
Reload the
.bashrc
file to apply changes immediately:source ~/.bashrc
How It Works:
- Every time you start WSL, it will check if Stable Diffusion is already running.
- If it isn’t, it will start the service silently with
--listen --api
.