├── keepwsl.service ├── readme.md └── install.sh /keepwsl.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=keepwsl.service 3 | 4 | [Service] 5 | Type=simple 6 | ExecStart=/mnt/c/Windows/System32/wsl.exe --exec /bin/sleep infinity 7 | Restart=always 8 | RestartSec=5 9 | 10 | [Install] 11 | WantedBy=default.target 12 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # keepwsl 2 | A simple service to keep WSL alive 3 | 4 | ## Prerequisite 5 | ### `/etc/wsl.conf` 6 | ```conf 7 | [boot] 8 | systemd=true 9 | 10 | [automount] 11 | enabled = true 12 | ``` 13 | 14 | ## Installation 15 | ``` 16 | sh -c "curl -sS https://raw.githubusercontent.com/gardengim/keepwsl/main/install.sh | sh" 17 | ``` 18 | ``` 19 | systemctl --user daemon-reload 20 | ``` 21 | ``` 22 | systemctl --user enable --now keepwsl 23 | ``` 24 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Check the pre-requisite 4 | # check if systemd is available 5 | if ! command -v systemctl >/dev/null 2>&1; then 6 | echo "systemd is not enabled in /etc/wsl.conf" 7 | exit 1 8 | fi 9 | 10 | # check if /mnt/c/Windows/System32/wsl.exe exists 11 | if [ ! -f /mnt/c/Windows/System32/wsl.exe ]; then 12 | echo "wsl.exe not found in /mnt/c/Windows/System32/" 13 | echo "automount may not be enabled in /etc/wsl.conf" 14 | exit 1 15 | fi 16 | 17 | # Download the keepwsl script 18 | mkdir -p ~/.config/systemd/user 19 | curl -fsSL https://raw.githubusercontent.com/gardengim/keepwsl/main/keepwsl.service -o ~/.config/systemd/user/keepwsl.service 20 | 21 | echo To enable the service, run: 22 | echo systemctl --user enable keepwsl.service 23 | echo To start the service, run: 24 | echo systemctl --user start keepwsl.service 25 | --------------------------------------------------------------------------------