Chinaunix首页 | 论坛 | 博客
  • 博客访问: 764827
  • 博文数量: 274
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 862
  • 用 户 组: 普通用户
  • 注册时间: 2015-10-24 15:31
个人简介

不合格的程序猿

文章分类

全部博文(274)

文章存档

2019年(3)

2018年(1)

2017年(4)

2016年(160)

2015年(106)

我的朋友

分类: 系统运维

2016-03-07 20:57:47


安装ldap,启动、停止、删除ldap



点击(此处)折叠或打开

  1. #!/bin/bash
  2. #. /tos/bin/functions

  3. LDAPPATH=/tmp/ldap_tos
  4. FILE_PATH=/tmp/openldap
  5. OPENLDAP_SRC=/tos/etc/openldap.tgz
  6. START_LOG=/tmp/openldap_start_log
  7. FILE_NAME=$0
  8. BOOL_TRUE=1
  9. BOOL_FALSE=0

  10. function is_openldap_dir_exist()
  11. {
  12.     ret=$BOOL_FALSE

  13.     if [ -d $LDAPPATH ]; then
  14.         echo "openldp install directory has existed." >>$START_LOG
  15.         ret=$BOOL_TRUE
  16.     fi

  17.     return $ret
  18. }

  19. function is_openldap_src_exit()
  20. {
  21.     if [ ! -f $OPENLDAP_SRC ]; then
  22.         echo "$OPENLDAP_SRC doesn\'t exist!" >>$START_LOG
  23.         ret=$BOOL_FALSE
  24.     else
  25.         echo "$OPENLDAP_SRC doesn't exist!" >>$START_LOG
  26.         ret=$BOOL_TRUE
  27.     fi

  28.     return $ret
  29. }

  30. function dec_ldap_src()
  31. {
  32.     echo "tar openldap packet" >>$START_LOG

  33.     is_openldap_src_exit
  34.     if [ $? -ne $BOOL_TRUE ]; then
  35.         echo -e "\n******************** $FILE_NAME done\n" >> $START_LOG
  36.         exit 1
  37.     else
  38.         echo "find $OPENLDAP_SRC" >>$START_LOG
  39.     fi

  40.     tar zxf $OPENLDAP_SRC -C /tmp >/null
  41.     if [ $? -ne 0 ];then
  42.         echo "tar error!" >>$START_LOG
  43.         rm -fr $FILE_PATH
  44.         echo -e "\n******************** openldap_start.sh done\n" >> $START_LOG
  45.         exit -1
  46.     fi

  47.     tar xzvf $FILE_PATH/ldap_tos.tgz -C /tmp >/null
  48.     if [ $? -ne 0 ];then
  49.         echo "tar error!" >>$START_LOG
  50.         rm -fr /tmp/ldap_tos/
  51.         echo -e "\n******************** openldap_start.sh done\n" >> $START_LOG
  52.         exit 1
  53.     fi

  54.     return 0
  55. }

  56. function prepare_ldap_env()
  57. {
  58.     cp $FILE_PATH/topsec.schema $LDAPPATH/openldap/etc/openldap/schema
  59.     cp $FILE_PATH/slapd.conf $LDAPPATH/openldap/etc/openldap/
  60.     cp $FILE_PATH/ldap.conf $LDAPPATH/openldap/etc/openldap/

  61.     echo "prepare ldap environment" >>$START_LOG
  62.     LD_LIBRARY_PATH_TMP="$LDAPPATH/BerkeleyDB/lib:$LDAPPATH/openssl/lib:$LDAPPATH/openldap/lib"

  63.     cat /etc/profile |grep $LD_LIBRARY_PATH_TMP >/null
  64.     if [ $? -ne 0 ];then
  65.             echo "" >> /etc/profile
  66.             echo "#$TIMENOW add for tos_ldap" >> /etc/profile
  67.             echo "env | grep LD_LIBRARY_PATH >/null" >> /etc/profile
  68.             echo "if [ \$? -ne 0 ]; then" >> /etc/profile
  69.             echo "    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH_TMP" >> /etc/profile
  70.             echo "else" >> /etc/profile
  71.             echo "    export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$LD_LIBRARY_PATH_TMP" >> /etc/profile
  72.             echo "fi" >> /etc/profile
  73.     fi
  74.     PATH_TMP="$LDAPPATH/BerkeleyDB/bin:$LDAPPATH/openssl/bin:$LDAPPATH/openldap/bin:$LDAPPATH/openldap/sbin"

  75.     cat /etc/profile |grep $PATH_TMP >/null
  76.     if [ $? -ne 0 ];then
  77.             echo "export PATH=\$PATH:$PATH_TMP" >> /etc/profile
  78.     fi

  79.     source /etc/profile

  80.     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LD_LIBRARY_PATH_TMP
  81.     export PATH=$PATH:$PATH_TMP

  82.     return 0
  83. }

  84. #run_openldap start / run_openldap stop
  85. function run_openldap()
  86. {
  87.     case $1 in
  88.         "start")
  89.          echo "start openldap" >>$START_LOG
  90.          $LDAPPATH/openldap/libexec/slapd &
  91.         
  92.          if [ $? -ne 0 ];then
  93.          echo "start openldap failed" >>$START_LOG
  94.          exit 1
  95.          fi
  96.             netstat -ntpl | grep slapd #--color=auto
  97.             ;;
  98.         "stop")
  99.             killall -9 slapd > /dev/null
  100.             ;;
  101.         *)
  102.             echo -e "run this function as the example: \n\trun_openldap \"start\" \n\tor \n\trun_openldap \"stop\""
  103.             exit 1
  104.             ;;
  105.     esac

  106.     return 0
  107. }

  108. function set_openldap_default_info()
  109. {
  110.     #<<__GSX
  111.     echo "ldapadd system default objects" >>$START_LOG
  112.     PWD=`pwd`
  113.     cd $FILE_PATH
  114.     ldapadd -x -D "cn=root,dc=tos,dc=com" -w better -f all.ldif >>$START_LOG
  115.     ldapadd -x -D "cn=root,dc=tos,dc=com" -w better -f default-gp.ldif >>$START_LOG
  116.     ldapadd -x -D "cn=root,dc=tos,dc=com" -w better -f group-anonymous.ldif >>$START_LOG
  117.     ldapadd -x -D "cn=root,dc=tos,dc=com" -w better -f user-anonymous.ldif >>$START_LOG
  118.     ldapadd -x -D "cn=root,dc=tos,dc=com" -w better -f add_ldap_user_global_config >>$START_LOG
  119.     #__GSX

  120.     return $?
  121. }

  122. function openldap()
  123. {
  124.     case $1 in
  125.         "install")
  126.         {
  127.             #first
  128.             is_openldap_dir_exist
  129.             if [ $? -eq $BOOL_TRUE ]; then
  130.              exit 0
  131.             fi
  132.             #second
  133.             dec_ldap_src
  134.             #third
  135.             prepare_ldap_env
  136.             #fourth
  137.             run_openldap "start"
  138.             if [ $? -ne 0 ];then
  139.              echo "start openldap failed" >>$START_LOG
  140.             else
  141.              echo "start openldap successfully" >>$START_LOG
  142.             fi
  143.         }
  144.         ;;
  145.         "uninstall")
  146.         {
  147.             echo -e "uninstall the openldap"
  148.             #first
  149.             run_openldap "stop"
  150.             #second
  151.             is_openldap_dir_exist
  152.             if [ $? -eq $BOOL_FALSE ]; then
  153.              exit 0
  154.             fi
  155.             #third
  156.             rm -rf $LDAPPATH > /dev/null
  157.             rm -rf $FILE_PATH > /dev/null
  158.             rm -rf $START_LOG > /dev/null
  159.         }
  160.         ;;
  161.         "start")
  162.         {
  163.             echo -e "start the openldap"
  164.             prepare_ldap_env
  165.             run_openldap "start"
  166.         }
  167.         ;;
  168.         "stop")
  169.         {
  170.             echo -e "stop the openldap"
  171.             run_openldap "stop"
  172.         }
  173.         ;;
  174.         "restart")
  175.         {
  176.             echo -e "restart the openldap"
  177.             run_openldap "stop"
  178.             run_openldap "start"
  179.         }
  180.         ;;
  181.         *)
  182.             echo -e "use this script as: \n\t$FILE_NAME {install | uninstall | start | stop | restart}"
  183.             ;;
  184.     esac
  185. }

  186. function help_info()
  187. {
  188.     echo -e "\t$FILE_NAME install\t----> install openldap"    
  189.     echo -e "\t$FILE_NAME uninstall\t----> uninstall openldap"    
  190.     echo -e "\t$FILE_NAME start\t\t----> start openldap"    
  191.     echo -e "\t$FILE_NAME stop\t\t----> stop openldap"    
  192.     echo -e "\t$FILE_NAME restart\t----> restart openldap"    

  193.     return 0
  194. }

  195. if [ $# -eq 1 ]; then
  196.     if [ $1 = "-e" ]; then
  197.         help_info
  198.         exit 0
  199.     fi

  200.     echo -e "\n\n******************** start $FILE_NAME\n" >> $START_LOG
  201.     openldap $1
  202.     echo -e "\n\n******************** done $FILE_NAME\n" >> $START_LOG
  203. fi

阅读(668) | 评论(0) | 转发(0) |
0

上一篇:slapcat.sh

下一篇:SSL连接建立过程分析(5)

给主人留下些什么吧!~~