From 9489a7eeeae753b144db0382423c432c0b4f960e Mon Sep 17 00:00:00 2001 From: Alex Landau Date: Mon, 8 Dec 2008 10:54:46 +0000 Subject: rapid-tunneling: - Added status checker. - Tunnel is backgrounded with start-stop-daemon. git-svn-id: svn+ssh://xorcom/home/svn/debs/components/rapid-tunneling@6438 283159da-0705-0410-b60c-f2062b4bb6ad --- Makefile | 2 +- rapid-tunneling | 2 +- rapid-tunneling-status | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ rapid-tunneling.spec | 5 +++-- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100755 rapid-tunneling-status diff --git a/Makefile b/Makefile index 1a1fdef..33c98a9 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PACKAGE = rapid-tunneling SPEC = rapid-tunneling.spec -SOURCES = rapid-tunneling +SOURCES = rapid-tunneling rapid-tunneling-status VER = $(shell awk '/^Version: / {print $$2}' $(SPEC)| head -n 1) REL = $(shell awk '/^Release: / {print $$2}' $(SPEC)| head -n 1) diff --git a/rapid-tunneling b/rapid-tunneling index 97bf167..92bd7c7 100755 --- a/rapid-tunneling +++ b/rapid-tunneling @@ -27,4 +27,4 @@ rm -rf $tmpdir # Remove host key of $host (in case it has changed) ssh-keygen -R $host # Run in background -setsid ssh -o 'StrictHostKeyChecking no' -o 'BatchMode yes' -o 'ServerAliveInterval 60' -T -p $port -i $HOME/key -R $tunnelport:127.0.0.1:22 -l $user $host < $HOME/ra-params.tar.gz +busybox start-stop-daemon -S -b -m -p $HOME/pid -x /bin/sh -- -c "exec ssh -o 'StrictHostKeyChecking no' -o 'BatchMode yes' -o 'ServerAliveInterval 60' -T -p $port -i $HOME/key -R $tunnelport:127.0.0.1:22 -l $user $host < $HOME/ra-params.tar.gz" diff --git a/rapid-tunneling-status b/rapid-tunneling-status new file mode 100755 index 0000000..e270ea1 --- /dev/null +++ b/rapid-tunneling-status @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ "$1" = "--help" ]; then + echo "Usage: $0 [-p] []" 1>&2 + echo " -p: Print only pid of SSH process (if connecting or connected)." 1>&2 + echo " Otherwise, print status" 1>&2 + echo " Exit code: 0 if connected, 1 if connecting, 2 if not connected." 1>&2 + echo " $0 -s []" 1>&2 + echo " -s: Stop the tunnel" 1>&2 + exit 255 +fi + +if [ "$1" = "-p" ]; then + showpid=1 + shift +elif [ "$1" = "-s" ]; then + stop=1 + shift +fi +pidfile="$1" +[ -z "$pidfile" ] && pidfile="$HOME/pid" + +connected() +{ + [ "$showpid" = 1 ] && echo $pid || echo "Connected" + exit 0 +} + +connecting() +{ + [ "$showpid" = 1 ] && echo $pid || echo "Connecting" + exit 1 +} + +not_connected() +{ + [ "$showpid" = 1 ] || echo "Not connected" + exit 2 +} + +stop_it() +{ + kill $pid 2>/dev/null + exit 0 +} + +pid=`cat "$pidfile" 2>/dev/null` +[ "$pid" ] || not_connected +kill -s 0 $pid 2>/dev/null || not_connected +for i in /proc/$pid/fd/*; do + socket=`readlink $i 2>/dev/null | sed -n 's/^socket:\[\(.*\)\]$/\1/p'` + [ "$socket" ] || continue + state=`awk '$10 == '"$socket"' {print $4}' /proc/net/tcp` + [ "$state" ] || continue + [ "$stop" = 1 ] && stop_it + [ "$state" = "01" ] && connected || connecting +done +not_connected diff --git a/rapid-tunneling.spec b/rapid-tunneling.spec index 3b0645e..5afe062 100644 --- a/rapid-tunneling.spec +++ b/rapid-tunneling.spec @@ -8,7 +8,7 @@ URL: http://www.xorcom.com/ Source: rapid-tunneling-%{version}.tar.gz #Patch0: libname.diff #Patch1: bristuff.diff -Requires: openssh-clients +Requires: openssh-clients busybox # Patch: libpri-1.2.3-cflags.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root @@ -49,6 +49,7 @@ and NAT routers via SSH port forwarding. %{__rm} -rf %{buildroot} %{__install} -m 755 -d %{buildroot}%{_sbindir} %{__install} -m 755 rapid-tunneling %{buildroot}%{_sbindir} +%{__install} -m 755 rapid-tunneling-status %{buildroot}%{_sbindir} %{__install} -m 755 -d %{buildroot}/var/lib/rapid-tunneling #%{__rm} -rf %{buildroot} @@ -80,5 +81,5 @@ fi #%{_sbindir}/* %changelog -* Sun Dec 7 2008 Alex Landau 1.0-1 +* Sun Dec 8 2008 Alex Landau 1.0-1 - Initial RPM release. -- cgit v1.2.3