Skip to content

Startup Script

This guide explains how to use the startup script feature in WSL Dashboard to automatically start services when your distribution boots up.

How to automatically start services on boot

1. Configure the script hook path

The entry point for this feature is located in the settings dialog of any installed distribution. Open the settings for your chosen distribution and enter the path to your startup script in the corresponding input field.

distro-startup-script

2. Example: Docker Container Startup Script

Here is an example script (init.sh) that demonstrates how to start Docker containers and other services automatically.

bash
root@cloud:/home# cat init.sh
#! /bin/bash

# Add logging for Docker startup to facilitate troubleshooting
LOG_FILE="/var/log/wsl-dashboard-example.log"
echo "$(date): Starting WSL initialization script..." >> $LOG_FILE

# 1. Stop Docker
echo "$(date): Attempting to stop Docker service..." >> $LOG_FILE
cd /home/docker/ && docker compose down >> $LOG_FILE 2>&1

# 2. Start Docker (For demonstration purposes, -d was not used)
echo "$(date): Attempting to start Docker service..." >> $LOG_FILE
cd /home/docker/ && docker compose up >> $LOG_FILE 2>&1
DOCKER_EXIT_CODE=$?
echo "$(date): Docker startup complete, exit code: $DOCKER_EXIT_CODE" >> $LOG_FILE

# 3. Start any service
/home/www/apps/hello-go/hello  >> $LOG_FILE 2>&1