#!/bin/sh
#
# mydns This shell script takes care of starting and stopping MyDNS.
#
# chkconfig: - 85 15
# description: MyDNS is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.
# probe: true
# processname: mydns
# pidfile: /var/run/mydns/mydns.pid
# config: /etc/mydns.conf
### BEGIN INIT INFO
# Provides:          mydns
# Required-Start:    $syslog $network
# Required-Stop:     $syslog $network
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Description:       MyDNS is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.
### END INIT INFO

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

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

# Check that networking is up.
is_yes "$NETWORKING" || return 0

[ -f /etc/mydns.conf ] || exit 0

[ -f /usr/sbin/mydns ] || exit 0

[ -d /var/run/mydns ] || mkdir -p /var/run/mydns

PIDFILE=/var/run/mydns/mydns.pid
LOCKFILE=/var/lock/subsys/mydns
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user mydns -- mydns --background --conf=/etc/mydns.conf
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --lockfile "$LOCKFILE" --expect-user mydns -- mydns
	RETVAL=$?
	return $RETVAL
}
reload()
{
	msg_reloading $name
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user mydns --name mydns -HUP -- mydns
	RETVAL=$?
	return $RETVAL
}
restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
        status --pidfile "$PIDFILE" --expect-user mydns -- mydns
        RETVAL=$?
	;;
    reload)
        reload
	;;
    restart)
        restart
        ;;
    condstop)
        if [ -e "$LOCKFILE" ]; then
        stop
        fi
        ;;
    condreload)
        if [ -e "$LOCKFILE" ]; then
        reload
        fi
        ;;
    condrestart)
        if [ -e "$LOCKFILE" ]; then
        restart
        fi
        ;;
    *)
    msg_usage "${0##*/} {start|stop|status|reload|restart|condstop|condrestart|condreload}"
    RETVAL=1
esac

exit $RETVAL
