#!/bin/sh
#
# ypxfrd:       Starts the ypxfrd daemon
#
# Version:      @(#) /etc/init.d/ypxfrd 1.0
#
# chkconfig: - 26 74
# description: ypxfrd should be started in addition to ypserv to accelerate \
#	       transferring yp maps.
# processname: ypxfrd
#
# See https://fedoraproject.org/wiki/Packaging:SysVInitScript for 
# the guidelines document.

# Source function library.
[ -f /etc/rc.d/init.d/functions ] || exit 0
. /etc/rc.d/init.d/functions

# getting the YP domain name
. /etc/sysconfig/network

execname="rpc.ypxfrd"
exec="/usr/sbin/$execname"
prog="ypxfrd"

lockfile=/var/lock/subsys/$prog
pidfile=/var/run/$prog.pid

start() {
    [ $UID -eq 0 ] || exit 4
    [ -x $exec ] || exit 5
    echo -n $"Starting YP map server: "
    daemon --pidfile=$pidfile $exec $YPXFRD_ARGS
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    [ $UID -eq 0 ] || exit 4
    [ -x $exec ] || exit 5
    echo -n $"Stopping YP map server: "
    killproc -p $pidfile $execname
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    echo -n $"Reloading securenets and ypserv.conf file:"
    killproc -p $pidfile $execname -HUP
    retval=$?
    echo
    return $retval
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status -p $pidfile -l $prog $execname
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

usage() {
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
}

# See how we were called.
case "$1" in
    start)
	rh_status_q && exit 0
	$1
	;;
    stop)
	rh_status_q || exit 0
	$1
	;;
    restart)
	$1
	;;
    reload)
	rh_status_q || exit 7
	$1
	;;
    force-reload)
	force_reload
	;;
    status)
	rh_status
	;;
    condrestart|try-restart)
	rh_status_q || exit 0
	restart
	;;
    usage)
	$1
	;;
    *)
	usage
	exit 2
esac
exit $?
