#!/bin/bash
#
# stunnel		This shell script takes care of starting and stop-
# 			ping stunnel
#
# chkconfig: 345 80 30
# description: Secure tunnel


# processname: stunnel
# config: /etc/stunnel/stunnel.conf
# pidfile: /var/run/stunnel/stunnel.pid


# Source function library.
. /etc/rc.d/init.d/functions


# Source stunnel configuration.
if [ -f /etc/sysconfig/stunnel ] ; then
. /etc/sysconfig/stunnel
fi


RETVAL=0
prog="stunnel"


start() {
  # Start daemons.
  
  echo -n $"Starting $prog: "
  if test -x /usr/sbin/stunnel ; then
  /usr/sbin/stunnel
  fi
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/stunnel
  return $RETVAL
}


stop() {
  # Stop daemons.
  echo -n $"Shutting down $prog: "
  killproc stunnel
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/stunnel
  return $RETVAL
}

# See how we were called.
case "$1" in
  start)
     start
     ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    RETVAL=$?
    ;;
condrestart)
  if [ -f /var/lock/subsys/stunnel ]; then
     stop
     start
     RETVAL=$?
  fi
  ;;
status)
  status stunnel
  RETVAL=$?
  ;;
*)
  echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  exit 1
esac

exit $RETVAL
