26.5. 配置/etc/rc.d/init.d/ldap脚本文件

配置你的/etc/rc.d/init.d/ldap脚本文件来启动和停止 LDAP 服务器。 创建 ldap 脚本文件,使用 touch/etc/rc.d/init.d/ldap并添加

               #!/bin/sh
               #
               # ldap	This shell script takes care of starting and stopping
               #	ldap servers (slapd and slurpd).
               #
               # chkconfig: - 70 40
               # description: LDAP stands for Lightweight Directory Access Protocol, used \
               #              for implementing the industry standard directory services.
               # processname: slapd
               # config: /etc/openldap/slapd.conf
               # pidfile: /var/run/slapd.pid

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

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

               # Check that networking is up.
               [ ${NETWORKING} = "no" ] && exit 0

               [ -f /usr/sbin/slapd ] || exit 0
               [ -f /usr/sbin/slurpd ] || exit 0

               RETVAL=0

               # See how we were called.
               case "$1" in
               start)
               # Start daemons.
               echo -n "Starting ldap: "
               daemon slapd
               RETVAL=$?
               if [ $RETVAL -eq 0 ]; then
               if grep -q "^replogfile" /etc/openldap/slapd.conf; then
               daemon slurpd
               RETVAL=$?
               [ $RETVAL -eq 0 ] && pidof slurpd | cut -f 1 -d " " > /var/run/slurpd
               fi
               fi
               echo
               [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ldap
               ;;
               stop)
               # Stop daemons.
               echo -n "Shutting down ldap: "
               killproc slapd
               RETVAL=$?
               if [ $RETVAL -eq 0 ]; then
               if grep -q "^replogfile" /etc/openldap/slapd.conf; then
               killproc slurpd
               RETVAL=$?
               fi
               fi
               echo
               if [ $RETVAL -eq 0 ]; then
               rm -f /var/lock/subsys/ldap
               rm -f /var/run/slapd.args
               fi
               ;;
               status)
               status slapd
               RETVAL=$?
               if [ $RETVAL -eq 0 ]; then
               if grep -q "^replogfile" /etc/openldap/slapd.conf; then
               status slurpd
               RETVAL=$?
               fi
               fi
               ;;
               restart)
               $0 stop
               $0 start
               RETVAL=$?
               ;;
               reload)
               killproc -HUP slapd
               RETVAL=$?
               if [ $RETVAL -eq 0 ]; then
               if grep -q "^replogfile" /etc/openldap/slapd.conf; then
               killproc -HUP slurpd
               RETVAL=$?
               fi
               fi
               ;;
               *)
               echo "Usage: $0 start|stop|restart|status}"
               exit 1
               esac

               exit $RETVAL
             

现在,使该脚本可执行并更改其默认权限
                 [root@deep] /# chmod 700  /etc/rc.d/init.d/ldap
               

使用以下命令为 OpenLDAP 创建符号 rc.d 链接
                 [root@deep] /# chkconfig --add ldap
               

重新启动服务器时,OpenLDAP 脚本不会自动启动 slapd 守护进程。 您可以通过执行以下命令更改其默认值
                 [root@deep] /# chkconfig --level 345 ldap on
               

使用以下命令手动启动 OpenLDAP 服务器
               [root@deep] /# /etc/rc.d/init.d/ldap start
             

               Starting ldap:                                             [  OK  ]