wsl-vpnkit icon indicating copy to clipboard operation
wsl-vpnkit copied to clipboard

Starting wsl-vpnkit from a service (/etc/init.d)

Open adpeyre opened this issue 1 year ago • 2 comments

Hello,

I try to start wsl-vpnkit from a service in /etc/init.d/ I realized that with the start-stop-daemon function.

EXECUTABLE="$WSL_VPNKIT_DIRECTORY/wsl-vpnkit"
log_begin_msg "Starting $SERVICE_NAME"
start-stop-daemon --start --background --no-close --exec "$EXECUTABLE" --pidfile "$SERVICE_PID_FILE" --make-pidfile  >> $SERVICE_LOG_FILE 2>&1

It works but when I close the terminal. wsl-vpnkit is in error : write failed 32: Broken pipe. Do you have an idea where it could come from ?

I precise I launch service wsl-vpnkit start in the bashrc if the service doesn't run.

Ty

adpeyre avatar May 04 '23 16:05 adpeyre

I bet when the terminal closes, WSL terminated wsl-gvproxy.exe. Can you try starting the service through wsl.exe? In previous versions of wsl-vpnkit, this was part of the workaround trying to get the processes to stay running.

wsl.exe -d YourDistro service wsl-vpnkit start

sakai135 avatar May 15 '23 22:05 sakai135

I bet when the terminal closes, WSL terminated wsl-gvproxy.exe. Can you try starting the service through wsl.exe? In previous versions of wsl-vpnkit, this was part of the workaround trying to get the processes to stay running.

wsl.exe -d YourDistro service wsl-vpnkit start

It appears that using disown might address this issue -- i.e. update wsl-vpnkit to define run as follows:

run () {
    echo "starting vm and gvproxy..."
    $VMEXEC_PATH \
        -url="stdio:$GVPROXY_PATH?listen-stdio=accept&debug=$DEBUG" \
        -iface="$TAP_NAME" \
        -stop-if-exist="" \
        -preexisting=1 \
        -debug=$DEBUG &
    sleep 1 & # wait to establish connection
    disown
    echo "started vm and gvproxy"
}

edgimar avatar Jun 02 '23 20:06 edgimar