#!/bin/sh
#=================================================================
# Begin sshd
#
# Description : Start clement daemon
# chkconfig: 2345 97 13
#
#=================================================================

### BEGIN INIT INFO
# Provides:            $clement
# Required-Start:      $dovecot $clamd $spamassassin
# Should-Start:
# Required-Stop:       sendsignals
# Should-Stop:
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   Starts clement daemon.
# Description:         Starts clement daemon.
# X-LFS-Provided-By:   LFS
### END INIT INFO

. /lib/lsb/init-functions

APPNAME=clement
DAEMON=clement
DAEMON_PID=/run/${DAEMON}.pid

# Some functions to make the below more readable

#loading load configuration file
if [ -f  /etc/sysconfig/$APPNAME ] ; then
  . /etc/sysconfig/$APPNAME
fi

#--------------------------------------------------------------
#to start clement daemon
#--------------------------------------------------------------
mng_daemon ()

{
case "$1" in
  start)
    /usr/lib/$APPNAME/support/starting.sh
    if [ $? != 0 ] ; then
      exit 1;
      fi
    log_info_msg "Starting ${DAEMON} Server..."
    start_daemon -f /usr/sbin/${DAEMON} $OPTIONS
    evaluate_retval
    ;;

  stop)
    log_info_msg "Stopping ${DAEMON} Server..."
    killproc -p ${DAEMON_PID} /usr/sbin/${DAEMON}
    evaluate_retval
    rm -fr ${DAEMON_PID}
    ;;

 esac
}

case "$1" in
      start	\
    | stop	\
    )
	mng_daemon $1
        ;;

    reload)
        log_info_msg "Reloading ${DAEMON} Server..."
        pid=`cat ${DAEMON_PID} 2>/dev/null`

        if [ -n "${pid}" ]; then
           kill -HUP "${pid}"
        else
           (exit 1)
        fi

        evaluate_retval
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    condrestart)
        pid=`cat ${DAEMON_PID} 2>/dev/null`
        if [ -n "${pid}"  -a -d /proc/$pid ]; then
	  $0 restart
	  fi
        ;;


    *)
        echo "Usage: $0 {start|stop|reload|restart|status}"
        exit 1
        ;;
esac

