/wsl-service

Helps WSL startup on your Windows boot.

Primary LanguagePython

WSL Service

  • Helps WSL(Windows Subsystem for Linux) startup on your Windows boot.
  • Automatically configure your Windows and WSL's static ip address, firewall, proxy ports.
  • WSL Service will startup and executes init commands your WSL without Windows logon.
  • You can run web server like as linux daemon with init commands.
  • You can configure your own settings with json file.

Requirements

  • Python 3 is required in your Windows.
  • Tested with Windows 10, Windows 11, Python 3.8, Python 3.9, Python 3.10, WSL2 Ubuntu-20.04, WSL2 Ubuntu-22.04

How to use

  • Download or clone this repository.
  • Execute wslservice.bat, to test if it works on your environment.
  • Follow next described step for automatic startup on Windows boot.
  • Register as Windows Service or Task Scheduler

How to register as Windows Service

To Install as Windows Service (Only for Windows 10)

  • Only works in Windows 10, has problem in Windows 11, does not allow mounted WLS directory permission while accessing thru Windows 11 File Explorer.
  1. Install NSSM(Non-Sucking Service Manager). Download form nssm.cc and install or install with following command. Windows administrator privileges are required.

    choco install nssm
  2. Register wslservice.bat as windows service. windows administrator privileges are required.

    nssm.exe install WSLService

  3. Open Windows Service panel with following command and start WSLService.

    services.msc
    

To Remove from Windows Service

  1. Open Windows Service panel with following command and stop WSLService.

    services.msc
    
  2. Remove with following command.

    nssm.exe remove WSLService

How to register as Task Scheduler

To Install as Task Scheduler (Recommended for windows 11)

  • Resolves WLS directory permission problem while accessing thru Windows 11 File Explorer.
  1. Install NirCmd. Download form nirsoft.net and install or install with following command. Windows administrator privileges are required.

    choco install nircmd
  2. Create new task with wslservice.bat script at Task Scheduler.

    taskschd.msc

    Create New Task

    General Tab

    Triggers Tab

    Actions Tab

    Program/script: nircmd

    Add arguments: elevatecmd exec hide "path/to/wsl-service/wslservice.bat"

    Start in: path/to/wsl-service

  3. If you want to execute manually for a specific purpose, or to create shortcut icon, use wslservicetask.bat file which run task registered at scheduler.

Your own configuration

Default settings fie is wsl-service/source/settings.json. Copy to wsl-service/settings.json then config your own settings.

  • BINDING_ADDRESS: Static local ip address for your WSL.
  • FIREWALL_ALLOWED_PORTS: Automatic registeration on Windows firewall allowed port.
  • PROXY_FORWARDING_TCP_PORTS: Automatic registeration on Windows proxy port forwarding.
  • INITD_SERVICES: Automatically executes startup services such as ssh, nginx, mysql, redis, ...
  • INITD_EXECUTES: Automatically executes additional commands on startup such as your own server.

TODO

  • Automatic Windows service registration.

Reference