]> git.sur5r.net Git - openldap/blob - tests/scripts/test050-syncrepl-multimaster
Faster server restart
[openldap] / tests / scripts / test050-syncrepl-multimaster
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2009 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $SYNCPROV = syncprovno; then 
20         echo "Syncrepl provider overlay not available, test skipped"
21         exit 0
22 fi 
23
24 MMR=${MMR-4}
25
26 if [ $MMR -gt 9 ]; then
27 MMR=9
28 fi
29
30 XDIR=$TESTDIR/srv
31 TMP=$TESTDIR/tmp
32
33 mkdir -p $TESTDIR
34
35 $SLAPPASSWD -g -n >$CONFIGPWF
36
37 if test x"$SYNCMODE" = x ; then
38         SYNCMODE=rp
39 fi
40 case "$SYNCMODE" in
41         ro)
42                 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
43                 ;;
44         rp)
45                 SYNCTYPE="type=refreshAndPersist"
46                 ;;
47         *)
48                 echo "unknown sync mode $SYNCMODE"
49                 exit 1;
50                 ;;
51 esac
52
53 #
54 # Test replication of dynamic config:
55 # - start servers
56 # - configure over ldap
57 # - populate over ldap
58 # - configure syncrepl over ldap
59 # - retrieve database over ldap and compare against expected results
60 #
61
62 echo "Initializing server configurations..."
63 n=1
64 while [ $n -le $MMR ]; do
65
66 DBDIR=${XDIR}$n/db
67 CFDIR=${XDIR}$n/slapd.d
68
69 mkdir -p ${XDIR}$n $DBDIR $CFDIR
70
71 $SLAPADD -F $CFDIR -n 0 <<EOF
72 dn: cn=config
73 objectClass: olcGlobal
74 cn: config
75 olcServerID: $n
76
77 dn: olcDatabase={0}config,cn=config
78 objectClass: olcDatabaseConfig
79 olcDatabase: {0}config
80 olcRootPW:< file://$CONFIGPWF
81 EOF
82
83 n=`expr $n + 1`
84 done
85
86 echo "Starting server 1 on TCP/IP port $PORT1..."
87 cd ${XDIR}1
88 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
89 PID=$!
90 if test $WAIT != 0 ; then
91     echo PID $PID
92     read foo
93 fi
94 KILLPIDS="$PID"
95 cd $TESTWD
96
97 sleep 1
98
99 echo "Using ldapsearch to check that server 1 is running..."
100 for i in 0 1 2 3 4 5; do
101         $LDAPSEARCH -s base -b "" -H $URI1 \
102                 'objectclass=*' > /dev/null 2>&1
103         RC=$?
104         if test $RC = 0 ; then
105                 break
106         fi
107         echo "Waiting 5 seconds for slapd to start..."
108         sleep 5
109 done
110
111 if test $RC != 0 ; then
112         echo "ldapsearch failed ($RC)!"
113         test $KILLSERVERS != no && kill -HUP $KILLPIDS
114         exit $RC
115 fi
116
117 echo "Inserting syncprov overlay on server 1..."
118 echo "" > $TMP
119 if [ "$SYNCPROV" = syncprovmod ]; then
120 cat <<EOF >> $TMP
121 dn: cn=module,cn=config
122 changetype: add
123 objectClass: olcModuleList
124 cn: module
125 olcModulePath: ../../../servers/slapd/overlays
126 olcModuleLoad: syncprov.la
127
128 EOF
129 fi
130 #
131 # Note that we configure a timeout here; it's possible for both
132 # servers to attempt to bind to each other while a modify to
133 # cn=config is in progress. When the modify pauses the thread pool
134 # neither server will progress. The timeout will drop the syncrepl
135 # attempt and allow the modifies to complete.
136 #
137 read CONFIGPW < $CONFIGPWF
138 echo "dn: cn=config" >> $TMP
139 echo "changetype: modify" >> $TMP
140 echo "replace: olcServerID" >> $TMP
141 n=1
142 while [ $n -le $MMR ]; do
143 PORT=`expr $BASEPORT + $n`
144 URI="ldap://${LOCALHOST}:$PORT/"
145 echo "olcServerID: $n $URI" >> $TMP
146 n=`expr $n + 1`
147 done
148
149 cat <<EOF >> $TMP
150
151 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
152 changetype: add
153 objectClass: olcOverlayConfig
154 objectClass: olcSyncProvConfig
155 olcOverlay: syncprov
156
157 dn: olcDatabase={0}config,cn=config
158 changetype: modify
159 add: olcSyncRepl
160 EOF
161
162 n=1
163 while [ $n -le $MMR ]; do
164 PORT=`expr $BASEPORT + $n`
165 URI="ldap://${LOCALHOST}:$PORT/"
166 echo "olcSyncRepl: rid=00$n provider=$URI binddn=\"cn=config\" bindmethod=simple" >> $TMP
167 echo "  credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
168 echo "  retry=\"3 10 300 5\" timeout=3" >> $TMP
169 n=`expr $n + 1`
170 done
171 echo "-" >> $TMP
172 echo "add: olcMirrorMode" >> $TMP
173 echo "olcMirrorMode: TRUE" >> $TMP
174 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >> $TESTOUT 2>&1
175 RC=$?
176 if test $RC != 0 ; then
177         echo "ldapmodify failed for syncrepl config ($RC)!"
178         test $KILLSERVERS != no && kill -HUP $KILLPIDS
179         exit $RC
180 fi
181
182 n=2
183 while [ $n -le $MMR ]; do
184 PORT=`expr $BASEPORT + $n`
185 URI="ldap://${LOCALHOST}:$PORT/"
186 LOG=$TESTDIR/slapd.$n.log
187 echo "Starting server $n on TCP/IP port $PORT..."
188 cd ${XDIR}$n
189 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING > $LOG 2>&1 &
190 SLAVEPID=$!
191 if test $WAIT != 0 ; then
192     echo SLAVEPID $SLAVEPID
193     read foo
194 fi
195 KILLPIDS="$KILLPIDS $SLAVEPID"
196 cd $TESTWD
197
198 sleep 1
199
200 echo "Using ldapsearch to check that server $n is running..."
201 for i in 0 1 2 3 4 5; do
202         $LDAPSEARCH -s base -b "" -H $URI \
203                 'objectclass=*' > /dev/null 2>&1
204         RC=$?
205         if test $RC = 0 ; then
206                 break
207         fi
208         echo "Waiting 5 seconds for slapd to start..."
209         sleep 5
210 done
211
212 if test $RC != 0 ; then
213         echo "ldapsearch failed ($RC)!"
214         test $KILLSERVERS != no && kill -HUP $KILLPIDS
215         exit $RC
216 fi
217
218 echo "Configuring syncrepl on server $n..."
219 cat <<EOF > $TMP
220 dn: olcDatabase={0}config,cn=config
221 changetype: modify
222 add: olcSyncRepl
223 EOF
224 j=1
225 while [ $j -le $MMR ]; do
226 P2=`expr $BASEPORT + $j`
227 U2="ldap://${LOCALHOST}:$P2/"
228 echo "olcSyncRepl: rid=00$j provider=$U2 binddn=\"cn=config\" bindmethod=simple" >> $TMP
229 echo "  credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
230 echo "  retry=\"3 10 300 5\" timeout=3" >> $TMP
231 j=`expr $j + 1`
232 done
233 cat <<EOF >> $TMP
234 -
235 add: olcMirrorMode
236 olcMirrorMode: TRUE
237 EOF
238 $LDAPMODIFY -D cn=config -H $URI -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
239 n=`expr $n + 1`
240 done
241
242 echo "Adding schema and databases on server 1..."
243 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
244 include: file://$ABS_SCHEMADIR/core.ldif
245
246 include: file://$ABS_SCHEMADIR/cosine.ldif
247
248 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
249
250 include: file://$ABS_SCHEMADIR/openldap.ldif
251
252 include: file://$ABS_SCHEMADIR/nis.ldif
253 EOF
254 RC=$?
255 if test $RC != 0 ; then
256         echo "ldapadd failed for schema config ($RC)!"
257         test $KILLSERVERS != no && kill -HUP $KILLPIDS
258         exit $RC
259 fi
260
261 echo "" > $TMP
262 if [ "$BACKENDTYPE" = mod ]; then
263 cat <<EOF >> $TMP
264 dn: cn=module,cn=config
265 objectClass: olcModuleList
266 cn: module
267 olcModulePath: ../../../servers/slapd/back-$BACKEND
268 olcModuleLoad: back_$BACKEND.la
269
270 EOF
271 fi
272
273 cat <<EOF >> $TMP
274 dn: olcDatabase={1}$BACKEND,cn=config
275 objectClass: olcDatabaseConfig
276 objectClass: olc${BACKEND}Config
277 olcDatabase: {1}$BACKEND
278 olcSuffix: $BASEDN
279 olcDbDirectory: ./db
280 olcRootDN: $MANAGERDN
281 olcRootPW: $PASSWD
282 EOF
283
284 n=1
285 while [ $n -le $MMR ]; do
286 PORT=`expr $BASEPORT + $n`
287 URI="ldap://${LOCALHOST}:$PORT/"
288
289 echo "olcSyncRepl: rid=01$n provider=$URI binddn=\"$MANAGERDN\" bindmethod=simple" >> $TMP
290 echo "  credentials=$PASSWD searchbase=\"$BASEDN\" $SYNCTYPE" >> $TMP
291 echo "  retry=\"3 10 300 5\" timeout=3" >> $TMP
292 n=`expr $n + 1`
293 done
294
295 cat <<EOF >> $TMP
296 olcMirrorMode: TRUE
297
298 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
299 objectClass: olcOverlayConfig
300 objectClass: olcSyncProvConfig
301 olcOverlay: syncprov
302 EOF
303 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
304 RC=$?
305 if test $RC != 0 ; then
306         echo "ldapadd failed for database config ($RC)!"
307         test $KILLSERVERS != no && kill -HUP $KILLPIDS
308         exit $RC
309 fi
310
311 case $BACKEND in
312 bdb | hdb)
313         $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
314 dn: olcDatabase={1}$BACKEND,cn=config
315 changetype: modify
316 add: olcDbIndex
317 olcDbIndex: objectClass,entryUUID,entryCSN eq
318 olcDbIndex: cn,uid pres,eq,sub
319 EOF
320         RC=$?
321         if test $RC != 0 ; then
322                 echo "ldapadd modify for database config ($RC)!"
323                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
324                 exit $RC
325         fi
326         ;;
327 esac
328
329 echo "Using ldapadd to populate server 1..."
330 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
331         >> $TESTOUT 2>&1
332 RC=$?
333 if test $RC != 0 ; then
334         echo "ldapadd failed for server 1 database ($RC)!"
335         test $KILLSERVERS != no && kill -HUP $KILLPIDS
336         exit $RC
337 fi
338
339 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
340 sleep $SLEEP2
341
342 n=1
343 while [ $n -le $MMR ]; do
344 PORT=`expr $BASEPORT + $n`
345 URI="ldap://${LOCALHOST}:$PORT/"
346
347 echo "Using ldapsearch to read config from server $n..."
348 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF  \
349         'objectclass=*' > $TESTDIR/server$n.out 2>&1
350 RC=$?
351
352 if test $RC != 0 ; then
353         echo "ldapsearch failed at server $n ($RC)!"
354         test $KILLSERVERS != no && kill -HUP $KILLPIDS
355         exit $RC
356 fi
357
358 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
359
360 n=`expr $n + 1`
361 done
362
363 n=2
364 while [ $n -le $MMR ]; do
365 echo "Comparing retrieved configs from server 1 and server $n..."
366 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
367
368 if test $? != 0 ; then
369         echo "test failed - server 1 and server $n configs differ"
370         test $KILLSERVERS != no && kill -HUP $KILLPIDS
371         exit 1
372 fi
373 n=`expr $n + 1`
374 done
375
376 n=1
377 while [ $n -le $MMR ]; do
378 PORT=`expr $BASEPORT + $n`
379 URI="ldap://${LOCALHOST}:$PORT/"
380
381 echo "Using ldapsearch to read all the entries from server $n..."
382 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
383         'objectclass=*' > $TESTDIR/server$n.out 2>&1
384 RC=$?
385
386 if test $RC != 0 ; then
387         echo "ldapsearch failed at server $n ($RC)!"
388         test $KILLSERVERS != no && kill -HUP $KILLPIDS
389         exit $RC
390 fi
391 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
392 n=`expr $n + 1`
393 done
394
395 n=2
396 while [ $n -le $MMR ]; do
397 echo "Comparing retrieved entries from server 1 and server $n..."
398 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
399
400 if test $? != 0 ; then
401         echo "test failed - server 1 and server $n databases differ"
402         test $KILLSERVERS != no && kill -HUP $KILLPIDS
403         exit 1
404 fi
405 n=`expr $n + 1`
406 done
407
408 echo "Using ldapadd to populate server 2..."
409 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
410         >> $TESTOUT 2>&1
411 RC=$?
412 if test $RC != 0 ; then
413         echo "ldapadd failed for server 2 database ($RC)!"
414         test $KILLSERVERS != no && kill -HUP $KILLPIDS
415         exit $RC
416 fi
417
418 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
419 sleep $SLEEP1
420
421 n=1
422 while [ $n -le $MMR ]; do
423 PORT=`expr $BASEPORT + $n`
424 URI="ldap://${LOCALHOST}:$PORT/"
425
426 echo "Using ldapsearch to read all the entries from server $n..."
427 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
428         'objectclass=*' > $TESTDIR/server$n.out 2>&1
429 RC=$?
430
431 if test $RC != 0 ; then
432         echo "ldapsearch failed at server $n ($RC)!"
433         test $KILLSERVERS != no && kill -HUP $KILLPIDS
434         exit $RC
435 fi
436 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
437 n=`expr $n + 1`
438 done
439
440 n=2
441 while [ $n -le $MMR ]; do
442 echo "Comparing retrieved entries from server 1 and server $n..."
443 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
444
445 if test $? != 0 ; then
446         echo "test failed - server 1 and server $n databases differ"
447         test $KILLSERVERS != no && kill -HUP $KILLPIDS
448         exit 1
449 fi
450 n=`expr $n + 1`
451 done
452
453 echo "Using ldapadd to populate server 3..."
454 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
455         << EOMODS >> $TESTOUT 2>&1
456 dn: cn=Server 3 Test,dc=example,dc=com
457 changetype: add
458 objectClass: device
459 cn: Server 3 Test
460 EOMODS
461 RC=$?
462 if test $RC != 0 ; then
463         echo "ldapadd failed for server 3 database ($RC)!"
464         test $KILLSERVERS != no && kill -HUP $KILLPIDS
465         exit $RC
466 fi
467
468 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
469 sleep $SLEEP1
470
471 n=1
472 while [ $n -le $MMR ]; do
473 PORT=`expr $BASEPORT + $n`
474 URI="ldap://${LOCALHOST}:$PORT/"
475
476 echo "Using ldapsearch to read all the entries from server $n..."
477 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
478         'objectclass=*' > $TESTDIR/server$n.out 2>&1
479 RC=$?
480
481 if test $RC != 0 ; then
482         echo "ldapsearch failed at server $n ($RC)!"
483         test $KILLSERVERS != no && kill -HUP $KILLPIDS
484         exit $RC
485 fi
486 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
487 n=`expr $n + 1`
488 done
489
490 n=2
491 while [ $n -le $MMR ]; do
492 echo "Comparing retrieved entries from server 1 and server $n..."
493 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
494
495 if test $? != 0 ; then
496         echo "test failed - server 1 and server $n databases differ"
497         test $KILLSERVERS != no && kill -HUP $KILLPIDS
498         exit 1
499 fi
500 n=`expr $n + 1`
501 done
502
503 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
504 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
505         >> $TESTOUT 2>&1 << EOADDS
506 dn: cn=To be deleted by server 1,dc=example,dc=com
507 changetype: add
508 objectClass: device
509 # no distinguished values, will be added by DSA
510
511 dn: cn=To be deleted by server 2,dc=example,dc=com
512 changetype: add
513 objectClass: device
514 # no distinguished values, will be added by DSA
515
516 dn: cn=To be deleted by server 3,dc=example,dc=com
517 changetype: add
518 objectClass: device
519 # no distinguished values, will be added by DSA
520
521 dn: cn=To be deleted by server 1,dc=example,dc=com
522 changetype: delete
523 EOADDS
524 RC=$?
525 if test $RC != 0 ; then
526         echo "ldapmodify failed for server 1 database ($RC)!"
527         test $KILLSERVERS != no && kill -HUP $KILLPIDS
528         exit $RC
529 fi
530
531 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
532 sleep $SLEEP1
533
534 n=1
535 while [ $n -le $MMR ]; do
536 PORT=`expr $BASEPORT + $n`
537 URI="ldap://${LOCALHOST}:$PORT/"
538
539 echo "Using ldapsearch to read all the entries from server $n..."
540 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
541         'objectclass=*' > $TESTDIR/server$n.out 2>&1
542 RC=$?
543
544 if test $RC != 0 ; then
545         echo "ldapsearch failed at server $n ($RC)!"
546         test $KILLSERVERS != no && kill -HUP $KILLPIDS
547         exit $RC
548 fi
549 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
550 n=`expr $n + 1`
551 done
552
553 n=2
554 while [ $n -le $MMR ]; do
555 echo "Comparing retrieved entries from server 1 and server $n..."
556 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
557
558 if test $? != 0 ; then
559         echo "test failed - server 1 and server $n databases differ"
560         test $KILLSERVERS != no && kill -HUP $KILLPIDS
561         exit 1
562 fi
563 n=`expr $n + 1`
564 done
565
566 echo "Using ldapmodify to delete entries from server 2..."
567 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
568         >> $TESTOUT 2>&1 << EOADDS
569 dn: cn=To be deleted by server 2,dc=example,dc=com
570 changetype: delete
571 EOADDS
572 RC=$?
573 if test $RC != 0 ; then
574         echo "ldapmodify failed for server 2 database ($RC)!"
575         test $KILLSERVERS != no && kill -HUP $KILLPIDS
576         exit $RC
577 fi
578
579 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
580 sleep $SLEEP1
581
582 echo "Using ldapmodify to delete entries from server 3..."
583 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
584         >> $TESTOUT 2>&1 << EOADDS
585 dn: cn=To be deleted by server 3,dc=example,dc=com
586 changetype: delete
587 EOADDS
588 RC=$?
589 if test $RC != 0 ; then
590         echo "ldapmodify failed for server 3 database ($RC)!"
591         test $KILLSERVERS != no && kill -HUP $KILLPIDS
592         exit $RC
593 fi
594
595 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
596 sleep $SLEEP1
597
598 n=1
599 while [ $n -le $MMR ]; do
600 PORT=`expr $BASEPORT + $n`
601 URI="ldap://${LOCALHOST}:$PORT/"
602
603 echo "Using ldapsearch to read all the entries from server $n..."
604 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
605         'objectclass=*' > $TESTDIR/server$n.out 2>&1
606 RC=$?
607
608 if test $RC != 0 ; then
609         echo "ldapsearch failed at server $n ($RC)!"
610         test $KILLSERVERS != no && kill -HUP $KILLPIDS
611         exit $RC
612 fi
613 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
614 n=`expr $n + 1`
615 done
616
617 n=2
618 while [ $n -le $MMR ]; do
619 echo "Comparing retrieved entries from server 1 and server $n..."
620 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
621
622 if test $? != 0 ; then
623         echo "test failed - server 1 and server $n databases differ"
624         test $KILLSERVERS != no && kill -HUP $KILLPIDS
625         exit 1
626 fi
627 n=`expr $n + 1`
628 done
629
630 # kill!
631 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
632 kill -HUP $KILLPIDS
633
634 # kill!
635 # test $KILLSERVERS != no && wait
636 wait
637
638 echo "Restarting servers..."
639 KILLPIDS=""
640
641 echo "Starting server 1 on TCP/IP port $PORT1..."
642 echo "======================= RESTART =======================" >> $LOG1
643 cd ${XDIR}1
644 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
645 PID=$!
646 if test $WAIT != 0 ; then
647     echo PID $PID
648     read foo
649 fi
650 KILLPIDS="$PID"
651 cd $TESTWD
652
653 sleep 1
654
655 echo "Using ldapsearch to check that server 1 is running..."
656 for i in 0 1 2 3 4 5; do
657         $LDAPSEARCH -s base -b "" -H $URI1 \
658                 'objectclass=*' > /dev/null 2>&1
659         RC=$?
660         if test $RC = 0 ; then
661                 break
662         fi
663         echo "Waiting 5 seconds for slapd to start..."
664         sleep 5
665 done
666
667 if test $RC != 0 ; then
668         echo "ldapsearch failed ($RC)!"
669         test $KILLSERVERS != no && kill -HUP $KILLPIDS
670         exit $RC
671 fi
672
673 n=2
674 while [ $n -le $MMR ]; do
675 PORT=`expr $BASEPORT + $n`
676 URI="ldap://${LOCALHOST}:$PORT/"
677 LOG=$TESTDIR/slapd.$n.log
678 echo "Starting server $n on TCP/IP port $PORT..."
679 cd ${XDIR}$n
680 echo "======================= RESTART =======================" >> $LOG
681 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING >> $LOG 2>&1 &
682 PID=$!
683 if test $WAIT != 0 ; then
684     echo PID $PID
685     read foo
686 fi
687 KILLPIDS="$KILLPIDS $PID"
688 cd $TESTWD
689 n=`expr $n + 1`
690 done
691
692 n=2
693 while [ $n -le $MMR ]; do
694 PORT=`expr $BASEPORT + $n`
695 URI="ldap://${LOCALHOST}:$PORT/"
696 echo "Using ldapsearch to check that server $n is running..."
697 for i in 0 1 2 3 4 5; do
698         $LDAPSEARCH -s base -b "" -H $URI \
699                 'objectclass=*' > /dev/null 2>&1
700         RC=$?
701         if test $RC = 0 ; then
702                 break
703         fi
704         echo "Waiting 5 seconds for slapd to start..."
705         sleep 5
706 done
707
708 if test $RC != 0 ; then
709         echo "ldapsearch failed ($RC)!"
710         test $KILLSERVERS != no && kill -HUP $KILLPIDS
711         exit $RC
712 fi
713 n=`expr $n + 1`
714 done
715
716 # Insert modifications and more tests here.
717 echo "Waiting $SLEEP1 seconds for servers to resync..."
718 sleep $SLEEP1
719
720 echo "Using ldapmodify to add/modify/delete entries from server 1..."
721 for i in 1 2 3 4 5 6 7 8 9 10; do
722 echo "  iteration $i"
723 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
724         >> $TESTOUT 2>&1 << EOMODS
725 dn: cn=Add-Mod-Del,dc=example,dc=com
726 changetype: add
727 cn: Add-Mod-Del
728 objectclass: organizationalRole
729
730 dn: cn=Add-Mod-Del,dc=example,dc=com
731 changetype: modify
732 replace: description
733 description: guinea pig
734 -
735
736 dn: cn=Add-Mod-Del,dc=example,dc=com
737 changetype: delete
738 EOMODS
739 RC=$?
740 if test $RC != 0 ; then
741         echo "ldapmodify failed for server 1 database ($RC)!"
742         test $KILLSERVERS != no && kill -HUP $KILLPIDS
743         exit $RC
744 fi
745 done
746
747 echo "Waiting $SLEEP1 seconds for servers to resync..."
748 sleep $SLEEP1
749
750 n=1
751 while [ $n -le $MMR ]; do
752 PORT=`expr $BASEPORT + $n`
753 URI="ldap://${LOCALHOST}:$PORT/"
754
755 echo "Using ldapsearch to read all the entries from server $n..."
756 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
757         'objectclass=*' > $TESTDIR/server$n.out 2>&1
758 RC=$?
759
760 if test $RC != 0 ; then
761         echo "ldapsearch failed at server $n ($RC)!"
762         test $KILLSERVERS != no && kill -HUP $KILLPIDS
763         exit $RC
764 fi
765 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
766 n=`expr $n + 1`
767 done
768
769 n=2
770 while [ $n -le $MMR ]; do
771 echo "Comparing retrieved entries from server 1 and server $n..."
772 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
773
774 if test $? != 0 ; then
775         echo "test failed - server 1 and server $n databases differ"
776         test $KILLSERVERS != no && kill -HUP $KILLPIDS
777         exit 1
778 fi
779 n=`expr $n + 1`
780 done
781
782 test $KILLSERVERS != no && kill -HUP $KILLPIDS
783
784 echo ">>>>> Test succeeded"
785
786 test $KILLSERVERS != no && wait
787
788 exit 0