Skip to content

Resolving interop-issue while running wsl-vpnkit as a systemd-service in own wsl-distro #247

@dabeck81

Description

@dabeck81

Description of issue:

I created my own wsl-distribution where I wanted to start the wsl-vpnkit immediatly with a systemd-service upon start.

For this I created a dockerfile containing following instructions:

RUN wget -cO wsl-vpnkit.tar.gz "https://github.com/sakai135/wsl-vpnkit/releases/download/v0.4.1/wsl-vpnkit.tar.gz" \
    && mkdir -p /opt/wsl-vpnkit \
    && tar --directory /opt/wsl-vpnkit --strip-components=1 -xf wsl-vpnkit.tar.gz app/wsl-vpnkit app/wsl-gvproxy.exe app/wsl-vm \
    && rm -r /wsl-vpnkit.tar.gz

RUN systemctl enable wsl-vpnkit

As you can see the wsl-vpnkit is installed under /opt/wsl-vpnkit

I adapted the wsl-vpnkit.service file to point to that directory, but I quickly encountered upon inspecting the journalctl-logs of the service, that I constantly received the wsl-gvproxy.exe is not executable due to WSL interop settings or Windows permissions-error

Solution implemented

The problem was that when the systemd-service started, there was no WSL_INTEROP environment variable set to point towards the socket used for running ".exe" files in a WSL-distro.

I came up with following solution while reading following WSL-thread around this issue: microsoft/WSL#5065

Adapt service-file as follows:

[Unit]
Description=wsl-vpnkit

[Service]
# for wsl-vpnkit setup as a standalone script
# important to set type to idle, we want the service to be one of the last ones to be executed
Type=idle
# before running the wsl-vpnkit script we want to provide the correct WSL_INTEROP variable
ExecStart=/bin/sh -c '. /etc/systemd/system/wsl-interop-env.sh; /opt/wsl-vpnkit/wsl-vpnkit'
Environment=VMEXEC_PATH=/opt/wsl-vpnkit/wsl-vm
Environment=GVPROXY_PATH=/opt/wsl-vpnkit/wsl-gvproxy.exe

Restart=always
KillMode=mixed

[Install]
WantedBy=multi-user.target

And here you have the wsl-interop-env.sh script that initializes the WSL_INTEROP variable:

#!/bin/sh

export WSL_INTEROP=
for socket in $(ls /run/WSL|sort -n); do
   if ss -elx | grep "$socket"; then
      export WSL_INTEROP=/run/WSL/$socket
   else
      rm $socket
   fi
done

Proposal as a change in wsl-vpnkit

Add a check in the wsl-vpnkit-script to set the WSL_INTEROP variable when it is empty/not existant based upon the code in the wsl-interop-env.sh script.

If you have another working proposal to run wsl-vpnkit as a service within your own distro, please let me know

Thanks for this awsome project

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions