Steps to Start Automatically When WSL Starts

  1. Edit .bashrc or .profile: Open the .bashrc file in your home directory:

    nano ~/.bashrc
  2. 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.
  3. Save and Exit: Save the file (Ctrl + O, then Enter) and exit (Ctrl + X).
  4. Apply Changes: Reload the .bashrc file to apply changes immediately:

    source ~/.bashrc

How It Works: