2004-09-09 15:12:20 +00:00
|
|
|
#!/bin/bash
|
2004-09-09 15:12:12 +00:00
|
|
|
#
|
|
|
|
# ypbind: Starts the ypbind Daemon
|
|
|
|
#
|
2004-09-09 15:13:09 +00:00
|
|
|
# Version: @(#) /etc/init.d/ypbind.init 1.3
|
2004-09-09 15:12:12 +00:00
|
|
|
#
|
2004-09-09 15:12:20 +00:00
|
|
|
# chkconfig: - 27 73
|
2004-09-09 15:12:12 +00:00
|
|
|
# description: This is a daemon which runs on NIS/YP clients and binds them \
|
|
|
|
# to a NIS domain. It must be running for systems based on glibc \
|
|
|
|
# to work as NIS clients, but it should not be enabled on systems \
|
|
|
|
# which are not using NIS.
|
|
|
|
# processname: ypbind
|
|
|
|
# config: /etc/yp.conf
|
|
|
|
|
2008-11-24 13:59:40 +00:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: $ypbind
|
|
|
|
# Required-Start: $network $syslog
|
|
|
|
# Required-Stop: $network $syslog
|
|
|
|
# Default-Start:
|
|
|
|
# Default-Stop: 0 1 2 3 4 5 6
|
|
|
|
# Short-Description: start|stop|restart|condrestart|try-restart|reload|force-reload|status NIS client
|
|
|
|
# Description: This is a daemon which runs on NIS/YP clients and binds them to a NIS domain
|
|
|
|
### END INIT INFO
|
|
|
|
|
2004-09-09 15:12:12 +00:00
|
|
|
OTHER_YPBIND_OPTS=""
|
|
|
|
|
|
|
|
# Source function library.
|
|
|
|
. /etc/init.d/functions
|
|
|
|
|
2004-09-09 15:12:15 +00:00
|
|
|
. /etc/sysconfig/network
|
|
|
|
|
2006-08-24 02:14:40 +00:00
|
|
|
# Check for and source configuration file otherwise set defaults
|
|
|
|
[ -f /etc/sysconfig/ypbind ] && . /etc/sysconfig/ypbind
|
|
|
|
|
2007-04-17 19:50:58 +00:00
|
|
|
# NISTIMEOUT should be a multiple of 15 since
|
|
|
|
# ypwhich has a hardcoded 15sec timeout
|
|
|
|
[ -z "$NISTIMEOUT" ] && NISTIMEOUT=45
|
2006-07-18 13:42:15 +00:00
|
|
|
|
2004-09-09 15:12:20 +00:00
|
|
|
# Check that networking is configured.
|
2006-12-01 21:10:33 +00:00
|
|
|
[ "${NETWORKING}" = "no" ] && exit 0
|
2004-09-09 15:12:20 +00:00
|
|
|
|
2006-08-31 14:11:25 +00:00
|
|
|
selinux_on() {
|
|
|
|
[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return
|
2007-04-17 19:50:58 +00:00
|
|
|
#echo $"Turning on allow_ypbind SELinux boolean"
|
2006-08-31 14:11:25 +00:00
|
|
|
setsebool allow_ypbind=1
|
|
|
|
}
|
|
|
|
|
|
|
|
selinux_off() {
|
|
|
|
[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return
|
|
|
|
allow_ypbind=0
|
|
|
|
. /etc/selinux/config
|
2007-04-17 13:18:53 +00:00
|
|
|
if [ -e /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local ]; then
|
2006-08-31 14:11:25 +00:00
|
|
|
. /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local
|
|
|
|
fi
|
|
|
|
if [ $allow_ypbind == 0 ]; then
|
2007-04-17 19:50:58 +00:00
|
|
|
#echo $"Turning off allow_ypbind SELinux boolean"
|
2006-08-31 14:11:25 +00:00
|
|
|
setsebool allow_ypbind=$allow_ypbind
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2004-09-09 15:12:12 +00:00
|
|
|
start() {
|
2004-09-09 15:12:15 +00:00
|
|
|
DOMAINNAME=`domainname`
|
|
|
|
if [ "$DOMAINNAME" = "(none)" -o "$DOMAINNAME" = "" ]; then
|
2007-09-17 13:03:39 +00:00
|
|
|
echo -n $"Setting NIS domain: "
|
2007-04-17 19:50:58 +00:00
|
|
|
if [ -n "$NISDOMAIN" ]; then
|
|
|
|
action $"domain is '$NISDOMAIN' " domainname $NISDOMAIN
|
|
|
|
else # See if the domain is set in config file
|
|
|
|
NISDOMAIN=`grep "domain" /etc/yp.conf | grep -v ^# | \
|
|
|
|
awk '{print $2}'`
|
|
|
|
if [ -n "$NISDOMAIN" ]; then
|
|
|
|
action $"domain is '$NISDOMAIN' " \
|
|
|
|
domainname $NISDOMAIN
|
|
|
|
else
|
|
|
|
action $"domain not found" /bin/false
|
|
|
|
logger -t ypbind $"domain not found"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
2004-09-09 15:12:15 +00:00
|
|
|
fi
|
2007-04-17 19:50:58 +00:00
|
|
|
echo -n $"Starting NIS service: "
|
|
|
|
selinux_on
|
2004-09-09 15:12:12 +00:00
|
|
|
daemon ypbind $OTHER_YPBIND_OPTS
|
2004-09-09 15:15:48 +00:00
|
|
|
RETVAL=$?
|
2004-09-09 15:12:12 +00:00
|
|
|
echo
|
2004-09-09 15:15:48 +00:00
|
|
|
if [ $RETVAL -ne 0 ]; then
|
2008-06-10 13:22:46 +00:00
|
|
|
#selinux_off
|
2007-04-17 19:50:58 +00:00
|
|
|
logger -t ypbind "failed to start!"
|
2004-09-09 15:15:48 +00:00
|
|
|
return $RETVAL
|
|
|
|
fi
|
2007-09-17 13:03:39 +00:00
|
|
|
echo -n $"Binding NIS service: "
|
2004-09-09 15:15:48 +00:00
|
|
|
# the following fixes problems with the init scripts continuing
|
2004-09-09 15:12:12 +00:00
|
|
|
# even when we are really not bound yet to a server, and then things
|
|
|
|
# that need NIS fail.
|
2008-01-11 22:28:15 +00:00
|
|
|
timeout=10
|
2008-05-23 11:25:23 +00:00
|
|
|
firsttime=1
|
|
|
|
SECONDS=0
|
|
|
|
while [ $SECONDS -lt $timeout ]; do
|
2008-01-11 22:28:15 +00:00
|
|
|
if /usr/sbin/rpcinfo -p | LC_ALL=C fgrep -q ypbind
|
|
|
|
then
|
2008-05-23 11:25:23 +00:00
|
|
|
if [ $firsttime -eq 1 ]; then
|
2008-01-11 22:28:15 +00:00
|
|
|
# reset timeout
|
|
|
|
timeout=$NISTIMEOUT
|
2008-05-23 11:25:23 +00:00
|
|
|
firsttime=0
|
2008-01-11 22:28:15 +00:00
|
|
|
fi
|
2007-04-17 19:50:58 +00:00
|
|
|
/usr/bin/ypwhich > /dev/null 2>&1
|
2008-05-23 11:25:23 +00:00
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL -eq 0 ]; then
|
2008-01-11 22:28:15 +00:00
|
|
|
break;
|
2008-05-23 11:25:23 +00:00
|
|
|
fi
|
2008-01-11 22:28:15 +00:00
|
|
|
fi
|
2008-05-23 11:25:23 +00:00
|
|
|
sleep 2
|
2008-11-24 13:59:40 +00:00
|
|
|
echo -n "."
|
2004-09-09 15:15:48 +00:00
|
|
|
done
|
2004-09-09 15:12:20 +00:00
|
|
|
if [ $RETVAL -eq 0 ]; then
|
2008-11-24 13:59:40 +00:00
|
|
|
logger -t ypbind \
|
|
|
|
"NIS domain: `domainname`, NIS server: `ypwhich 2> /dev/null`"
|
|
|
|
touch /var/lock/subsys/ypbind
|
|
|
|
success
|
2004-09-09 15:12:20 +00:00
|
|
|
else
|
2008-11-24 13:59:40 +00:00
|
|
|
logger -t ypbind \
|
|
|
|
"NIS server for domain `domainname` is not responding."
|
|
|
|
failure
|
|
|
|
#selinux_off
|
2007-04-17 19:50:58 +00:00
|
|
|
RETVAL=100
|
2004-09-09 15:12:20 +00:00
|
|
|
fi
|
|
|
|
echo
|
2004-09-09 15:12:12 +00:00
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2007-04-17 19:50:58 +00:00
|
|
|
echo -n $"Shutting down NIS service: "
|
2004-09-09 15:12:12 +00:00
|
|
|
killproc ypbind
|
|
|
|
RETVAL=$?
|
2008-11-24 13:59:40 +00:00
|
|
|
if [ $RETVAL -eq 0 ]; then
|
2007-04-17 19:50:58 +00:00
|
|
|
rm -f /var/lock/subsys/ypbind
|
|
|
|
# if we used brute force (like kill -9) we don't want those around
|
2008-11-24 13:59:40 +00:00
|
|
|
if [ x$(domainname) != x ]; then
|
2007-04-17 19:50:58 +00:00
|
|
|
rm -f /var/yp/binding/$(domainname)*
|
|
|
|
fi
|
2004-09-09 15:12:12 +00:00
|
|
|
fi
|
|
|
|
echo
|
2008-06-10 13:22:46 +00:00
|
|
|
#selinux_off
|
2004-09-09 15:12:12 +00:00
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
}
|
|
|
|
|
2008-11-24 13:59:40 +00:00
|
|
|
reload() {
|
|
|
|
echo -n $"Reloading NIS service: "
|
|
|
|
p=`/sbin/pidof -o %PPID 'ypbind'`
|
|
|
|
RETVAL=$?
|
|
|
|
if [ "$RETVAL" -eq 0 ]; then
|
|
|
|
/bin/kill -HUP $p
|
|
|
|
RETVAL=$?
|
|
|
|
fi
|
|
|
|
[ "$RETVAL" -eq 0 ] && success || failure
|
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
2004-09-09 15:12:12 +00:00
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
# See how we were called.
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2008-11-24 13:59:40 +00:00
|
|
|
start
|
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL -eq 100 ]; then stop; RETVAL=1; fi
|
2004-09-09 15:12:12 +00:00
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
2008-11-24 13:59:40 +00:00
|
|
|
RETVAL=$?
|
2004-09-09 15:12:12 +00:00
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status ypbind
|
2007-09-17 13:03:39 +00:00
|
|
|
RETVAL=$?
|
2004-09-09 15:12:12 +00:00
|
|
|
;;
|
2008-11-24 13:59:40 +00:00
|
|
|
restart)
|
2004-09-09 15:12:12 +00:00
|
|
|
restart
|
2008-11-24 13:59:40 +00:00
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
condrestart|try-restart)
|
|
|
|
if [ -e /var/lock/subsys/ypbind ]; then restart; fi
|
|
|
|
;;
|
|
|
|
reload)
|
|
|
|
reload
|
2004-09-09 15:12:12 +00:00
|
|
|
;;
|
2008-11-24 13:59:40 +00:00
|
|
|
force-reload)
|
|
|
|
if ! reload; then restart; fi
|
2004-09-09 15:12:12 +00:00
|
|
|
;;
|
|
|
|
*)
|
2008-11-24 13:59:40 +00:00
|
|
|
echo $"Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status}"
|
|
|
|
RETVAL=3
|
2004-09-09 15:12:12 +00:00
|
|
|
esac
|
|
|
|
|
2008-11-24 13:59:40 +00:00
|
|
|
exit $RETVAL
|