#!/bin/sh
#
# chkconfig: - 91 35
# description: Starts and stops the ISPCP daemon
#
# pidfile: /var/run/ispcp.pid
# config:  /etc/ispcp/ispcp.conf
#
# ispCP ω (OMEGA) a Virtual Hosting Control Panel
# Copyright (C) 2006-2010 by isp Control Panel - http://ispcp.net
#
# Version: $Id: ispcp_daemon 2505 2010-01-06 20:30:53Z nuxwin $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is "ispCP ω (OMEGA) a Virtual Hosting Control Panel".
#
# The Initial Developer of the Original Code is ispCP Team.
# Portions created by Initial Developer are Copyright (C) 2006-2010 by
# isp Control Panel. All Rights Reserved.
#
# The ispCP ω Home Page is:
#
#    http://isp-control.net
#

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Avoid using root's TMPDIR
unset TMPDIR

# Source networking configuration.
. /etc/sysconfig/network

if [ -f /var/www/ispcp/daemon ]; then
   . /var/www/ispcp/daemon
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# Check that ispcp.conf exists.
[ -f /etc/ispcp/ispcp.conf ] || exit 0

RETVAL=0


start() {
        KIND="ISPCP"
	echo -n $"Starting $KIND services: "
	daemon /var/www/ispcp/daemon/ispcp_daemon
	RETVAL=$?
	echo
      	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ispcp || RETVAL=1
	echo ""
	return $RETVAL
}

stop() {
        KIND="ISPCP"
	echo -n $"Shutting down $KIND services: "
	killproc ispcp_daemon
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ispcp
	echo ""
	return $RETVAL
}

restart() {
	stop
	start
}

reload() {
        echo -n $"Reloading ispcp.conf: "
	killproc ispcp_daemon -HUP
	RETVAL=$?
	echo
	return $RETVAL
}

rhstatus() {
	status ispcp_daemon
	RETVAL=$?
	if [ $? -ne 0 -o $RETVAL -ne 0 ] ; then
		return 1
	fi
}


# Allow status as non-root.
if [ "$1" = status ]; then
       rhstatus
       exit $?
fi

# Check that we can write to it... so non-root users stop here
[ -w /etc/ispcp/ispcp.conf ] || exit 0



case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/ispcp ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
	exit 1
esac

exit $?
