Skip to content

Commit 7793c2d

Browse files
committed
Add pid file
1 parent 80d87e5 commit 7793c2d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ chisel
55
id_rsa.pub
66
ssh_host_rsa_key
77
ssh_host_rsa_key.pub
8+
9+
# Ignore any pid files
10+
tunnel-*.pid

tunnel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cd `dirname $0`
66

77
appname="cf-ssh-chisel-$USER"
88
echo "Starting $appname forwarding local port ${CHISEL_LOCAL_PORT:=5022} to remote port ${CHISEL_REMOTE_PORT:=2022}"
9+
pidfile=tunnel-${CHISEL_LOCAL_PORT}.pid
910

1011
echo "Checking if $appname is running"
1112
cf app $appname > /dev/null # Make sure app is there
@@ -23,6 +24,11 @@ url=`cf app $appname | egrep 'routes|urls' | awk '{print $2}'`
2324
echo "$url" | grep "$appname" | grep -q predix.io || { echo "URL doesn't look sane: $url"; exit 2; }
2425

2526
# If there's an existing client running, kill it
27+
if [ -r "$pidfile" ]; then
28+
kill $(cat "$pidfile") 2>/dev/null
29+
rm "$pidfile"
30+
fi
31+
2632
client_pids=`ps auxww | grep ./chisel | grep ${CHISEL_LOCAL_PORT}:${CHISEL_REMOTE_PORT} | grep -v grep | awk '{print $2}'`
2733
if [ -n "$client_pids" ]; then
2834
kill $client_pids
@@ -32,6 +38,7 @@ echo "Starting client, connecting to $url"
3238
cmd="./chisel client --keepalive 10s https://$url ${CHISEL_LOCAL_PORT}:${CHISEL_REMOTE_PORT}"
3339
echo "Running in background: $cmd"
3440
$cmd > /dev/null &
41+
echo $# > "$pidfile"
3542

3643
cat <<_EOF_
3744
You can now connect via

0 commit comments

Comments
 (0)