#!/sbin/runscript # Copyright 1999-2008 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ depend() { need net use dns local service="${SVCNAME#*.}" master="$(get_value master)" source /etc/conf.d/autossh [[ -n "$master" && "$master" != "no" ]] && need autossh.$master [[ "$(type -t depend_$service)" == "function" ]] && eval depend_$service } get_value() { source /etc/conf.d/autossh _get_value() { for i in "$@"; do if [[ -z "$varname" ]]; then varname="${i}" else varname="${varname}_${i}" fi done eval echo "${!varname}" } local retval service="${SVCNAME#*.}" retval="$(_get_value "$service" "$@")" if [[ -z "$retval" ]]; then retval="$(_get_value "global" "$@")" fi echo "$retval" return 0 } start() { local service="${SVCNAME#*.}" interval="$(get_value alive_interval)" host="$(get_value host)" master="$(get_value master)" myargs debug="$(get_value debug)" ssdargs if [[ "$service" == "autossh" ]]; then eerror "Autossh must be started as a symlink (autossh.svcname)" return 1 fi [[ -z "$interval" ]] && interval="15" if [[ -z "$host" && -z "$master" ]]; then eerror "No host/master specified for service $service" return 1 fi if [[ ! -f "/var/log/autossh-$service.log" ]]; then touch "/var/log/autossh-$service.log" chown autossh:daemon "/var/log/autossh-$service.log" fi if [[ -z "$master" ]]; then myargs="${myargs} -o ControlMaster=yes" myargs="${myargs} -o ControlPath=/var/run/autossh/control-%r@%h-%p.sock" elif [[ "$master" != "no" ]]; then myargs="${myargs} -o ControlMaster=no" myargs="${myargs} -o ControlPath=/var/run/autossh/control-%r@%h-%p.sock" if [[ -n "$host" ]]; then eerror "Only one of host/master may be specified." return 1 else host="$(SVCNAME="$master" get_value host)" fi fi myargs="${myargs} -o ConnectionAttempts=3" myargs="${myargs} -o BatchMode=yes" myargs="${myargs} -o EscapeChar=none" myargs="${myargs} -o ExitOnForwardFailure=yes" myargs="${myargs} -o ServerAliveInterval=$interval" myargs="${myargs} -o ForwardAgent=no" ssdargs="${ssdargs} --start" ssdargs="${ssdargs} --exec /usr/bin/autossh" ssdargs="${ssdargs} --pidfile /var/run/autossh/autossh-$service.pid" ssdargs="${ssdargs} --user autossh:daemon" ssdargs="${ssdargs} --env AUTOSSH_PORT=0" ssdargs="${ssdargs} --env AUTOSSH_LOGFILE=/var/log/autossh-$service.log" ssdargs="${ssdargs} --env AUTOSSH_PIDFILE=/var/run/autossh/autossh-$service.pid" ssdargs="${ssdargs} --chdir /var/lib/autossh" ssdargs="${ssdargs} --umask 0077" if [[ -z "$debug" ]]; then ebegin "Starting autossh instance $service" start-stop-daemon ${ssdargs} -- \ -T \ -n \ -f \ -N \ $myargs \ $(get_value args) \ $(get_value args add) \ "$host" eend $? "Failed to start autossh instance $service" else ebegin "Starting autossh instance $service in debug mode" start-stop-daemon ${ssdargs} \ --env AUTOSSH_LOGLEVEL="7" \ --env AUTOSSH_DEBUG="true" \ --stdout "/var/lib/autossh/$service.stdout" \ --stderr "/var/lib/autossh/$service.stderr" \ --background \ --verbose \ -- \ -n \ -T \ -N \ -o "LogLevel=DEBUG3" \ $myargs \ $(get_value args) \ $(get_value args add) \ "$host" eend $? "Failed to start autossh instance $service" fi } stop() { local service="${SVCNAME#*.}" ebegin "Stopping autossh instance $service" start-stop-daemon --stop \ --pidfile "/var/run/autossh/autossh-$service.pid" \ --exec /usr/bin/autossh eend $? "Failed to stop autossh instance $service" }