Skip to content

Instantly share code, notes, and snippets.

@oxyflour
Forked from jeremija/autossh
Last active February 3, 2016 01:09
Show Gist options
  • Save oxyflour/d7e91fa545ca1e46855b to your computer and use it in GitHub Desktop.
Save oxyflour/d7e91fa545ca1e46855b to your computer and use it in GitHub Desktop.
raspi autossh
#! /bin/sh
# /etc/init.d/autossh
TUNNEL_MONITOR=53389
TUNNEL_USER="bae"
TUNNEL_HOST="bae.ofr.me"
TUNNEL_PORT=30383
TUNNEL_KEY="/home/oxyflour/.ssh/bae.id_rsa"
TUNNEL_ARGS="-D 0.0.0.0:3129 -L 0.0.0.0:13128:127.0.0.1:3128 -L 0.0.0.0:10022:vlr.ofr.me:22"
DAEMON=/usr/lib/autossh/autossh
NAME=`basename $0`
PIDFILE=/var/run/$NAME.pid
export AUTOSSH_PIDFILE=$PIDFILE
export AUTOSSH_LOGLEVEL=7
export AUTOSSH_FIRST_POLL=60
export AUTOSSH_POLL=60
case "$1" in
start)
echo "Starting $NAME..."
if start-stop-daemon --start -v \
--pidfile $PIDFILE \
--exec $DAEMON \
-- \
-f -N \
-M $TUNNEL_MONITOR \
$TUNNEL_ARGS \
-i $TUNNEL_KEY \
-p $TUNNEL_PORT \
$TUNNEL_USER@$TUNNEL_HOST
then
echo "Started $NAME."
fi
;;
stop)
echo "Stopping $NAME..."
# --quiet is required to terminate the ssh process forked by autossh
if start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
then
echo "Stopped $NAME."
fi
;;
status)
if start-stop-daemon --status --pidfile $PIDFILE
then
echo "$NAME is running."
else
echo "$NAME is stopped."
fi
;;
*)
echo "Usage: service $NAME {start|stop|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment