Skip to content

Commit 8f36071

Browse files
committed
Improve pid handling
1 parent cf309f9 commit 8f36071

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

tunnel

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ echo "$url" | grep "$appname" | grep -q predix.io || { echo "URL doesn't look sa
2525

2626
# If there's an existing client running, kill it
2727
if [ -r "$pidfile" ]; then
28-
kill $(cat "$pidfile") 2>/dev/null
29-
rm "$pidfile"
30-
fi
28+
pid=$(cat "$pidfile")
3129

32-
client_pids=`ps auxww | grep ./chisel | grep ${CHISEL_LOCAL_PORT}:${CHISEL_REMOTE_PORT} | grep -v grep | awk '{print $2}'`
33-
if [ -n "$client_pids" ]; then
34-
kill $client_pids
30+
# Note ps will exit non-0 if $pid isn't running
31+
ps -p $pid | grep -q chisel && kill $pid
32+
rm "$pidfile"
3533
fi
3634

3735
echo "Starting client, connecting to $url"

0 commit comments

Comments
 (0)