#!/bin/sh
# POP3 Daemon
#
# chkconfig:	345 80 20
# description:	POP3 Daemon

sysconfdir=/etc/courier-imap
libexecdir=/usr/lib64/courier-imap
sbindir=/usr/sbin

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

# Get network config
. /etc/sysconfig/network

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down "Courier POP3"
		exit 1
	fi
else
	exit 0
fi

RETVAL=0
# See how we were called.
case "$1" in
start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/courier-pop3 ]; then
		msg_starting pop3d
		daemon $libexecdir/pop3d.rc start
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/courier-pop3
	else
		msg_already_running pop3d
	fi
;;
stop)
	if [ -f /var/lock/subsys/courier-pop3 ]; then
		msg_stopping pop3d
		daemon $libexecdir/pop3d.rc stop
		RETVAL=$?
		rm -f /var/lock/subsys/courier-pop3 >/dev/null 2>&1
	else
		msg_not_running pop3d
	fi
;;
restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
status)
	status couriertcpd
	exit $?
	;;
*)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
