start-dirsrv.in 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/sh
  2. # Script that starts the ns-slapd server.
  3. # Exit status can be:
  4. # 0: Server started successfully
  5. # 1: Server could not be started
  6. # 2: Server already running
  7. . @datadir@/@package_name@/data/DSSharedLib
  8. # Starts a single instance
  9. start_instance() {
  10. # The first argument is the server ID. Anything
  11. # after that is an argument to ns-slapd.
  12. SERV_ID=$1
  13. shift
  14. initfile=`get_init_file $initconfig_dir $SERV_ID` || { echo Instance $SERV_ID not found. ; return 1 ; }
  15. # source env. for this instance
  16. if [ -f $initfile ] ; then
  17. . $initfile
  18. else
  19. echo Instance $SERV_ID not found.
  20. return 1
  21. fi
  22. prefix="$DS_ROOT"
  23. libpath_add "$prefix$SERVER_DIR"
  24. libpath_add "$prefix@nss_libdir@"
  25. libpath_add "$prefix@libdir@"
  26. libpath_add "@nss_libdir@"
  27. libpath_add "$prefix@pcre_libdir@"
  28. export LD_LIBRARY_PATH
  29. SHLIB_PATH=$LD_LIBRARY_PATH
  30. export SHLIB_PATH
  31. DS_CONFIG_DIR=$CONFIG_DIR
  32. export DS_CONFIG_DIR
  33. PIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.pid
  34. STARTPIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.startpid
  35. if test -f $STARTPIDFILE ; then
  36. PID=`cat $STARTPIDFILE`
  37. if kill -s 0 $PID > /dev/null 2>&1 ; then
  38. echo There is an ns-slapd process already running: $PID
  39. return 2;
  40. else
  41. rm -f $STARTPIDFILE
  42. fi
  43. fi
  44. if test -f $PIDFILE ; then
  45. PID=`cat $PIDFILE`
  46. if kill -s 0 $PID > /dev/null 2>&1 ; then
  47. echo There is an ns-slapd running: $PID
  48. return 2;
  49. else
  50. rm -f $PIDFILE
  51. fi
  52. fi
  53. #
  54. # Use systemctl if available and running as root,
  55. # otherwise start the instance the old way.
  56. #
  57. if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then
  58. @bindir@/systemctl start @package_name@@$SERV_ID.service
  59. if [ $? -ne 0 ]; then
  60. return 1
  61. fi
  62. else
  63. $SERVERBIN_DIR/ns-slapd -D $CONFIG_DIR -i $PIDFILE -w $STARTPIDFILE "$@"
  64. if [ $? -ne 0 ]; then
  65. return 1
  66. fi
  67. fi
  68. loop_counter=1
  69. # wait for 10 seconds for the start pid file to appear
  70. max_count=${STARTPID_TIME:-10}
  71. while test $loop_counter -le $max_count; do
  72. loop_counter=`expr $loop_counter + 1`
  73. if test ! -f $STARTPIDFILE ; then
  74. sleep 1;
  75. else
  76. PID=`cat $STARTPIDFILE`
  77. fi
  78. done
  79. if test ! -f $STARTPIDFILE ; then
  80. echo Server failed to start !!! Please check errors log for problems
  81. return 1
  82. fi
  83. loop_counter=1
  84. # wait for 10 minutes (600 times 1 seconds)
  85. max_count=${PID_TIME:-600}
  86. while test $loop_counter -le $max_count; do
  87. loop_counter=`expr $loop_counter + 1`
  88. if test ! -f $PIDFILE ; then
  89. if kill -s 0 $PID > /dev/null 2>&1 ; then
  90. sleep 1
  91. else
  92. echo Server failed to start !!! Please check errors log for problems
  93. return 1
  94. fi
  95. else
  96. PID=`cat $PIDFILE`
  97. rm -f $STARTPIDFILE
  98. return 0;
  99. fi
  100. done
  101. echo Server not running!! Failed to start ns-slapd process. Please check the errors log for problems.
  102. return 1
  103. }
  104. # source env. for all instances
  105. [ -f @initconfigdir@/@package_name@ ] && . @initconfigdir@/@package_name@
  106. while getopts "d:" flag
  107. do
  108. case "$flag" in
  109. d) initconfig_dir="$OPTARG";;
  110. esac
  111. done
  112. shift $(($OPTIND-1))
  113. if [ -z "$initconfig_dir" ]; then
  114. initconfig_dir=@initconfigdir@
  115. fi
  116. found=0
  117. if [ $# -eq 0 ]; then
  118. # We're starting all instances.
  119. ret=0
  120. initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; }
  121. for i in $initfiles; do
  122. inst=`normalize_server_id $i`
  123. echo Starting instance \"$inst\"
  124. start_instance $inst
  125. rv=$?
  126. if [ $rv -ne 0 ]; then
  127. ret=$rv
  128. fi
  129. done
  130. exit $ret
  131. else
  132. # We're starting a single instance.
  133. start_instance $@
  134. exit $?
  135. fi