Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
autosshd is the autossh daemon.
#!/bin/bash
#
# autosshd This script starts and stops the autossh daemon
#
# chkconfig: 2345 95 15
# processname: autosshd
# description: autosshd is the autossh daemon.
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
TUNNEL_SSHCONFIG="/etc/appliance/.tunnel/ssh_config"
TUNNEL_IDENTITY="/etc/appliance/.tunnel/identity"
TUNNEL_HOST="tunnel"
export AUTOSSH_PIDFILE="/var/run/autossh.pid"
# By default it's all good.
RETVAL=0
# Start function.
start() {
local name=$1
echo -n $"Starting ${name}: "
if [ -e "/var/lock/subsys/${name}" ]; then
if [ -e "/var/run/${name}.pid" ] && [ -e /proc/`cat /var/run/${name}.pid` ]; then
echo -n $"already exists.";
failure $"already exists.";
echo
return 1
fi
fi
daemon /usr/bin/autossh -M 0 -f -nNT -F ${TUNNEL_SSHCONFIG} -i ${TUNNEL_IDENTITY} ${TUNNEL_HOST}
RETVAL=$?
[ $RETVAL -eq 0 ] && touch "/var/lock/subsys/${name}"
echo
return $RETVAL
}
# Stop function.
stop() {
local name=$1
echo -n $"Stopping ${name}: "
killproc -p "/var/run/${name}.pid" ${name}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f "/var/lock/subsys/${name}"
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start "autossh"
;;
stop)
stop "autossh"
;;
restart)
$0 stop
sleep 3
$0 start
;;
status)
status "autossh"
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment