#!/bin/bash # # ypbind: Starts the ypbind Daemon # # Version: @(#) /etc/init.d/ypbind.init 1.3 # # chkconfig: - 27 73 # 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 ### 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 OTHER_YPBIND_OPTS="" # Source function library. . /etc/init.d/functions . /etc/sysconfig/network # Check for and source configuration file otherwise set defaults [ -f /etc/sysconfig/ypbind ] && . /etc/sysconfig/ypbind # NISTIMEOUT should be a multiple of 15 since # ypwhich has a hardcoded 15sec timeout [ -z "$NISTIMEOUT" ] && NISTIMEOUT=45 # Check that networking is configured. [ "${NETWORKING}" = "no" ] && exit 0 selinux_on() { [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return #echo $"Turning on allow_ypbind SELinux boolean" setsebool allow_ypbind=1 } selinux_off() { [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return allow_ypbind=0 . /etc/selinux/config if [ -e /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local ]; then . /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local fi if [ $allow_ypbind == 0 ]; then #echo $"Turning off allow_ypbind SELinux boolean" setsebool allow_ypbind=$allow_ypbind fi } start() { DOMAINNAME=`domainname` if [ "$DOMAINNAME" = "(none)" -o "$DOMAINNAME" = "" ]; then echo -n $"Setting NIS domain: " 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 fi echo -n $"Starting NIS service: " selinux_on daemon ypbind $OTHER_YPBIND_OPTS RETVAL=$? echo if [ $RETVAL -ne 0 ]; then #selinux_off logger -t ypbind "failed to start!" return $RETVAL fi echo -n $"Binding NIS service: " # the following fixes problems with the init scripts continuing # even when we are really not bound yet to a server, and then things # that need NIS fail. timeout=10 firsttime=1 SECONDS=0 while [ $SECONDS -lt $timeout ]; do if /usr/sbin/rpcinfo -p | LC_ALL=C fgrep -q ypbind then if [ $firsttime -eq 1 ]; then # reset timeout timeout=$NISTIMEOUT firsttime=0 fi /usr/bin/ypwhich > /dev/null 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ]; then break; fi fi sleep 2 echo -n "." done if [ $RETVAL -eq 0 ]; then logger -t ypbind \ "NIS domain: `domainname`, NIS server: `ypwhich 2> /dev/null`" touch /var/lock/subsys/ypbind success else logger -t ypbind \ "NIS server for domain `domainname` is not responding." failure #selinux_off RETVAL=100 fi echo return $RETVAL } stop() { echo -n $"Shutting down NIS service: " killproc ypbind RETVAL=$? if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/ypbind # if we used brute force (like kill -9) we don't want those around if [ x$(domainname) != x ]; then rm -f /var/yp/binding/$(domainname)* fi fi echo #selinux_off return $RETVAL } restart() { stop start } 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 } RETVAL=0 # See how we were called. case "$1" in start) start RETVAL=$? if [ $RETVAL -eq 100 ]; then stop; RETVAL=1; fi ;; stop) stop RETVAL=$? ;; status) status ypbind RETVAL=$? ;; restart) restart RETVAL=$? ;; condrestart|try-restart) if [ -e /var/lock/subsys/ypbind ]; then restart; fi ;; reload) reload ;; force-reload) if ! reload; then restart; fi ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status}" RETVAL=3 esac exit $RETVAL