Skip to content

Commit

Permalink
Revert "Improve service init script and logs (#147)"
Browse files Browse the repository at this point in the history
This reverts commit dc94c08.
  • Loading branch information
sakai135 committed Nov 17, 2022
1 parent ed4f38c commit b95b4fb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 120 deletions.
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ Start `wsl-vpnkit` from your other WSL 2 distros. Add the command to your `.prof
wsl.exe -d wsl-vpnkit --cd /app service wsl-vpnkit start
```

You can also check service status to start service only if needed.

```sh
wsl.exe -d wsl-vpnkit --cd /app service wsl-vpnkit status >/dev/null || \
wsl.exe -d wsl-vpnkit --cd /app service wsl-vpnkit start
```

### Notes

* Ports on the WSL 2 VM are accessible from the Windows host using `localhost`.
Expand Down Expand Up @@ -64,8 +57,8 @@ This will build and import the distro.
```sh
git clone https://github.com/sakai135/wsl-vpnkit.git
cd wsl-vpnkit/
./build.sh
./test.sh

./distro/test.sh
```

## Using `wsl-vpnkit` as a standalone script
Expand Down Expand Up @@ -120,12 +113,3 @@ wsl.exe -d wsl-vpnkit --cd /app wsl-vpnkit
wsl --shutdown
kill -Name wsl-gvproxy
```

### Run service with debug

If you set DEBUG variable before calling service you can see more debug information

Example:
```sh
wsl.exe -d wsl-vpnkit --cd /app DEBUG=1 service wsl-vpnkit restart
```
6 changes: 1 addition & 5 deletions distro/scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ touch $LOG_PATH

echo "
wsl-vpnkit $VERSION
This distro is only intended for running wsl-vpnkit.
This distro is only intended for running wsl-vpnkit.
Run the following commands from Windows or other WSL 2 distros to use.
Expand All @@ -23,10 +23,6 @@ Logs for wsl-vpnkit can be viewed here.
wsl.exe -d $WSL_DISTRO_NAME --cd /app tail -f $LOG_PATH
To see only the most recent logs
wsl.exe -d $WSL_DISTRO_NAME --cd /app sh -c \"tac $LOG_PATH | awk '{print}; /starting wsl-vpnkit/{exit}' | tac\"
Config for wsl-vpnkit can be edited here.
$USERPROFILE/wsl-vpnkit/wsl-vpnkit.conf
Expand Down
48 changes: 4 additions & 44 deletions distro/scripts/wsl-vpnkit.service
Original file line number Diff line number Diff line change
@@ -1,61 +1,27 @@
#! /bin/sh

EXECUTABLE="wsl-vpnkit" # starting point
SUB_PROCESS="wsl-vm" # forked sub processes
PID_PATH="/var/run/$EXECUTABLE.pid"
LOG_PATH="/var/log/$EXECUTABLE.log"
PID_PATH="/var/run/wsl-vpnkit.pid"
LOG_PATH="/var/log/wsl-vpnkit.log"

ret=0

_debug_check() {
if [ -n "$DEBUG" ]; then
set -x
test -f $PID_PATH && cat $PID_PATH
ps
fi
}

start() {
_debug_check
start-stop-daemon \
--pidfile $PID_PATH \
--make-pidfile \
--background \
--stdout $LOG_PATH \
--stderr $LOG_PATH \
--exec $EXECUTABLE \
${DEBUG+--verbose} \
--exec wsl-vpnkit \
--start
ret=$?
}

stop() {
_debug_check
start-stop-daemon \
--pidfile $PID_PATH \
--retry 2 \
${DEBUG+--verbose} \
--stop
ret=$?
# kill sub processes if still running
pgrep $SUB_PROCESS >/dev/null && pkill -9 $SUB_PROCESS
}

status() {
_debug_check
test -f $PID_PATH && pgrep -P $(cat $PID_PATH) &>/dev/null
ret=$?
if [ $ret = 0 ]; then
echo Service $EXECUTABLE is running
else
echo Service $EXECUTABLE is not running
fi
}

restart() {
stop
start
ret=$?
}

case "$1" in
Expand All @@ -65,14 +31,8 @@ case "$1" in
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $EXECUTABLE {start|stop|restart|status}"
echo "Usage: wsl-vpnkit {start|stop}"
exit 1
esac

Expand Down
7 changes: 3 additions & 4 deletions build.sh → distro/test.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#! /bin/sh -xe
#! /bin/sh -e

# run from repo root
# ./build.sh
# ./distro/test.sh

USERPROFILE="$(powershell.exe -c 'Write-Host -NoNewline $env:USERPROFILE')"
DUMP=wsl-vpnkit.tar.gz
TAG_NAME=wslvpnkit

# build
docker build -t $TAG_NAME -f ./distro/Dockerfile .
CONTAINER_ID=$(docker create $TAG_NAME)
docker export $CONTAINER_ID | gzip > $DUMP
docker container rm $CONTAINER_ID
ls -la $DUMP

# reinstall
wsl.exe --unregister wsl-vpnkit || :
wsl.exe --import wsl-vpnkit --version 2 "$USERPROFILE\\wsl-vpnkit" $DUMP
rm $DUMP
wsl.exe -d wsl-vpnkit
49 changes: 0 additions & 49 deletions test.sh

This file was deleted.

0 comments on commit b95b4fb

Please sign in to comment.