3 # Kill me on all errors
6 # Stop processing if slapd is not there
7 [ -x /usr/sbin/slapd ] || exit 0
10 DB_RECOVER_CMD=db4.2_recover
12 # Source the init script configuration
13 if [ -f "/etc/default/slapd" ]; then
17 # Load the default location of the slapd config file
18 if [ -z "$SLAPD_CONF" ]; then
19 SLAPD_CONF="/etc/ldap/slapd.conf"
21 SLAPD_OPTIONS="-f $SLAPD_CONF $SLAPD_OPTIONS"
22 SLURPD_OPTIONS="-f $SLAPD_CONF $SLURPD_OPTIONS"
25 # Stop processing if the config file is not there
26 if [ ! -r "$SLAPD_CONF" ]; then
28 No configuration file was found for slapd at $SLAPD_CONF.
29 If you have moved the slapd configuration file please modify
30 /etc/default/slapd to reflect this. If you chose to not
31 configure slapd during installation then you need to do so
32 prior to attempting to start slapd.
33 An example slapd.conf is in /usr/share/slapd
35 exit 0 # Should this be 1?
38 # Figure out some default settings
39 # Check wether slurpd should get started
40 if [ "$SLURPD_START" != "yes" ] && [ "$SLURPD_START" != "no" ]; then
41 if grep -q '^replica' "$SLAPD_CONF" > /dev/null 2>&1 ; then
48 # Find out the name of slapd's pid file
49 if [ -z "$SLAPD_PIDFILE" ]; then
50 SLAPD_PIDFILE=`sed -ne 's/^pidfile[[:space:]]\+\(.\+\)/\1/p' \
54 # XXX: Breaks upgrading if there is no pidfile (invoke-rc.d stop will fail)
56 if [ -z "$SLAPD_PIDFILE" ]; then
58 The pidfile for slapd is neither specified in "$SLAPD_CONF" nor
59 in /etc/default/slapd. Consequently, slapd will not be started.
64 # Pass the user and group to run under to slapd
65 if [ "$SLAPD_USER" ]; then
66 SLAPD_OPTIONS="-u $SLAPD_USER $SLAPD_OPTIONS"
69 if [ "$SLAPD_GROUP" ]; then
70 SLAPD_OPTIONS="-g $SLAPD_GROUP $SLAPD_OPTIONS"
73 # Tell the user that something went wrong and give some hints for
74 # resolving the problem.
76 if [ -n "$reason" ]; then
82 The operation failed but no output was produced. For hints on what went
83 wrong please refer to the system's logfiles (e.g. /var/log/syslog) or
84 try running the daemon in Debug mode like via "slapd -d 16383" (warning:
85 this will create copious output).
88 if [ -n "$SLURPD_OPTIONS" -o \
89 -n "$SLAPD_OPTIONS" -o \
90 -n "$SLAPD_SERVICES" ]; then
93 Below, you can find the command line options used by this script to
94 run slapd and slurpd. Do not forget to specify those options if you
95 want to look to debugging output:
97 if [ -z "$SLAPD_SERVICES" ]; then
98 if [ -n "$SLAPD_OPTIONS" ]; then
99 echo " slapd $SLAPD_OPTIONS"
102 echo " slapd -h '$SLAPD_SERVICES' $SLAPD_OPTIONS"
105 if [ "$SLURPD" = "yes" -a -n "$SLURPD_OPTIONS" ]; then
106 echo " slurpd $SLURPD_OPTIONS"
112 # Try to recover slapd database
114 local dbdir failed bdb_envs
116 # db4.2-util is just recommended by slapd, so make sure it is
117 # available before trying to use it
118 if ! command -v $DB_RECOVER_CMD >/dev/null 2>&1; then
119 echo -n " ($DB_RECOVER_CMD not found), "
123 bdb_envs=`find_bdb_envs`
125 # We care only about BDB environments
126 if [ -z "$bdb_envs" ]; then
130 # Make sure there is no slapcat and no slapd running as we might
131 # break the DB in that case
132 if pidof /usr/lib/slapd >/dev/null; then
133 echo -n " (slapd running, no recovery), "
137 echo -n " running BDB recovery"
138 for dbdir in $bdb_envs; do
139 reason="`$DB_RECOVER_CMD -eh $dbdir 2>&1`" || \
140 db_recover_failed $dbdir
145 # Find bdb environment dirs
148 for d in `sed -ne 's/^directory[[:space:]]\+"*\([^"]\+\).*/\1/p' \
150 if [ -d "$d" -a -f "$d/objectClass.bdb" ]; then
156 # Inform the user that BDB recovery failed
157 db_recover_failed() {
162 Automatic recovery of the OpenLDAP directory database in
166 failed. You will need to perform a manual recovery, possibly from backup.
167 The failed command was $DB_RECOVER_CMD -eh $dbdir. Output:
174 # Start the slapd daemon and capture the error message if any to
178 if [ -z "$SLAPD_SERVICES" ]; then
179 reason="`start-stop-daemon --start --quiet --oknodo \
180 --pidfile "$SLAPD_PIDFILE" \
181 --exec /usr/sbin/slapd -- $SLAPD_OPTIONS 2>&1`"
183 reason="`start-stop-daemon --start --quiet --oknodo \
184 --pidfile "$SLAPD_PIDFILE" \
185 --exec /usr/sbin/slapd -- -h "$SLAPD_SERVICES" $SLAPD_OPTIONS 2>&1`"
189 # Start the slurpd daemon and capture the error message if any to
192 if [ "$SLURPD_START" != yes ]; then
196 reason="`start-stop-daemon --start --quiet --oknodo \
197 --exec /usr/sbin/slurpd -- $SLURPD_OPTIONS 2>&1`"
200 # Stop the slapd daemon and capture the error message (if any) to
204 reason="`start-stop-daemon --stop --quiet --oknodo --retry 10 \
205 --pidfile "$SLAPD_PIDFILE" \
206 --exec /usr/sbin/slapd 2>&1`"
209 # Stop the slurpd daemon and capture the error message (if any) to
212 if [ "$SLURPD_START" != yes ]; then
216 reason="`start-stop-daemon --stop --quiet --oknodo --retry 10 \
217 --exec /usr/sbin/slurpd 2>&1`"
220 # Start the OpenLDAP daemons
222 echo -n "Starting OpenLDAP:"
223 trap 'report_failure' 0
224 if [ "$TRY_BDB_RECOVERY" = "yes" ]; then
233 # Stop the OpenLDAP daemons
235 echo -n "Stopping OpenLDAP:"
236 trap 'report_failure' 0
248 restart|force-reload)
253 echo "Usage: $0 {start|stop|restart|force-reload}"