Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: slapd2
  4. # Required-Start: $remote_fs $network $syslog
  5. # Required-Stop: $remote_fs $network $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: OpenLDAP standalone server (Lightweight Directory Access Protocol)
  9. ### END INIT INFO
  10.  
  11. # Specify path variable
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13.  
  14. . /lib/lsb/init-functions
  15.  
  16. # Kill me on all errors
  17. set -e
  18.  
  19. # Set the paths to slapd as a variable so that someone who really
  20. # wants to can override the path in /etc/default/slapd.
  21. SLAPD=/usr/sbin/slapd2
  22.  
  23. # Stop processing if slapd is not there
  24. [ -x $SLAPD ] || exit 0
  25.  
  26. # debconf may have this file descriptor open and it makes things work a bit
  27. # more reliably if we redirect it as a matter of course. db_stop will take
  28. # care of this, but this won't hurt.
  29. exec 3>/dev/null
  30.  
  31. # Source the init script configuration
  32. if [ -f "/etc/default/slapd2" ]; then
  33. . /etc/default/slapd2
  34. fi
  35.  
  36. # Load the default location of the slapd config file
  37. if [ -z "$SLAPD_CONF" ]; then
  38. if [ -e /etc/ldap2/slapd.d ]; then
  39. SLAPD_CONF=/etc/ldap2/slapd.d
  40. else
  41. SLAPD_CONF=/etc/ldap/slapd.conf
  42. fi
  43. fi
  44.  
  45. # Stop processing if the config file is not there
  46. if [ ! -r "$SLAPD_CONF" ]; then
  47. log_warning_msg "No configuration file was found for slapd at $SLAPD_CONF."
  48. # if there is no config at all, we should assume slapd is not running
  49. # and exit 0 on stop so that unconfigured packages can be removed.
  50. [ "x$1" = xstop ] && exit 0 || exit 1
  51. fi
  52.  
  53. # extend options depending on config type
  54. if [ -f "$SLAPD_CONF" ]; then
  55. SLAPD_OPTIONS="-f $SLAPD_CONF $SLAPD_OPTIONS"
  56. elif [ -d "$SLAPD_CONF" ] ; then
  57. SLAPD_OPTIONS="-F $SLAPD_CONF $SLAPD_OPTIONS"
  58. fi
  59.  
  60. # Find out the name of slapd's pid file
  61. if [ -z "$SLAPD_PIDFILE" ]; then
  62. # If using old one-file configuration scheme
  63. if [ -f "$SLAPD_CONF" ] ; then
  64. SLAPD_PIDFILE=`sed -ne 's/^pidfile[[:space:]]\+\(.\+\)/\1/p' \
  65. "$SLAPD_CONF"`
  66. # Else, if using new directory configuration scheme
  67. elif [ -d "$SLAPD_CONF" ] ; then
  68. SLAPD_PIDFILE=`sed -ne \
  69. 's/^olcPidFile:[[:space:]]\+\(.\+\)[[:space:]]*/\1/p' \
  70. "$SLAPD_CONF"/'cn=config.ldif'`
  71. fi
  72. fi
  73.  
  74. # XXX: Breaks upgrading if there is no pidfile (invoke-rc.d stop will fail)
  75. # -- Torsten
  76. if [ -z "$SLAPD_PIDFILE" ]; then
  77. log_failure_msg "The pidfile for slapd has not been specified"
  78. exit 1
  79. fi
  80.  
  81. # Make sure the pidfile directory exists with correct permissions
  82. piddir=`dirname "$SLAPD_PIDFILE"`
  83. if [ ! -d "$piddir" ]; then
  84. mkdir -p "$piddir"
  85. [ -z "$SLAPD_USER" ] || chown -R "$SLAPD_USER" "$piddir"
  86. [ -z "$SLAPD_GROUP" ] || chgrp -R "$SLAPD_GROUP" "$piddir"
  87. fi
  88.  
  89. # Pass the user and group to run under to slapd
  90. if [ "$SLAPD_USER" ]; then
  91. SLAPD_OPTIONS="-u $SLAPD_USER $SLAPD_OPTIONS"
  92. fi
  93.  
  94. if [ "$SLAPD_GROUP" ]; then
  95. SLAPD_OPTIONS="-g $SLAPD_GROUP $SLAPD_OPTIONS"
  96. fi
  97.  
  98. # Check whether we were configured to not start the services.
  99. check_for_no_start() {
  100. if [ -n "$SLAPD_NO_START" ]; then
  101. echo 'Not starting slapd: SLAPD_NO_START set in /etc/default/slapd' >&2
  102. exit 0
  103. fi
  104. if [ -n "$SLAPD_SENTINEL_FILE" ] && [ -e "$SLAPD_SENTINEL_FILE" ]; then
  105. echo "Not starting slapd: $SLAPD_SENTINEL_FILE exists" >&2
  106. exit 0
  107. fi
  108. }
  109.  
  110. # Tell the user that something went wrong and give some hints for
  111. # resolving the problem.
  112. report_failure() {
  113. log_end_msg 1
  114. if [ -n "$reason" ]; then
  115. log_failure_msg "$reason"
  116. else
  117. log_failure_msg "The operation failed but no output was produced."
  118.  
  119. if [ -n "$SLAPD_OPTIONS" -o \
  120. -n "$SLAPD_SERVICES" ]; then
  121. if [ -z "$SLAPD_SERVICES" ]; then
  122. if [ -n "$SLAPD_OPTIONS" ]; then
  123. log_failure_msg "Command line used: slapd $SLAPD_OPTIONS"
  124. fi
  125. else
  126. log_failure_msg "Command line used: slapd -h '$SLAPD_SERVICES' $SLAPD_OPTIONS"
  127. fi
  128. fi
  129. fi
  130. }
  131.  
  132. # Start the slapd daemon and capture the error message if any to
  133. # $reason.
  134. start_slapd() {
  135. if [ -z "$SLAPD_SERVICES" ]; then
  136. reason="`start-stop-daemon --start --quiet --oknodo \
  137. --pidfile "$SLAPD_PIDFILE" \
  138. --exec $SLAPD -- $SLAPD_OPTIONS 2>&1`"
  139. else
  140. reason="`start-stop-daemon --start --quiet --oknodo \
  141. --pidfile "$SLAPD_PIDFILE" \
  142. --exec $SLAPD -- -h "$SLAPD_SERVICES" $SLAPD_OPTIONS 2>&1`"
  143. fi
  144.  
  145. # Backward compatibility with OpenLDAP 2.1 client libraries.
  146. if [ ! -h /var/run/ldapi ] && [ ! -e /var/run/ldapi ] ; then
  147. ln -s slapd/ldapi /var/run/ldapi
  148. fi
  149. }
  150.  
  151. # Stop the slapd daemon and capture the error message (if any) to
  152. # $reason.
  153. stop_slapd() {
  154. reason="`start-stop-daemon --stop --quiet --oknodo --retry TERM/10 \
  155. --pidfile "$SLAPD_PIDFILE" \
  156. --exec $SLAPD 2>&1`"
  157. }
  158.  
  159. # Start the OpenLDAP daemons
  160. start_ldap() {
  161. trap 'report_failure' 0
  162. log_daemon_msg "Starting OpenLDAP" "slapd"
  163. start_slapd
  164. trap "-" 0
  165. log_end_msg 0
  166. }
  167.  
  168. # Stop the OpenLDAP daemons
  169. stop_ldap() {
  170. trap 'report_failure' 0
  171. log_daemon_msg "Stopping OpenLDAP" "slapd"
  172. stop_slapd
  173. trap "-" 0
  174. log_end_msg 0
  175. }
  176.  
  177. case "$1" in
  178. start)
  179. check_for_no_start
  180. start_ldap ;;
  181. stop)
  182. stop_ldap ;;
  183. restart|force-reload)
  184. check_for_no_start
  185. stop_ldap
  186. start_ldap
  187. ;;
  188. status)
  189. status_of_proc -p $SLAPD_PIDFILE $SLAPD slapd
  190. ;;
  191. *)
  192. echo "Usage: $0 {start|stop|restart|force-reload|status}"
  193. exit 1
  194. ;;
  195. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement