22
33FIRST_START_DONE=" /etc/docker-openldap-first-start-done"
44WAS_STARTED_WITH_TLS=" /etc/ldap/slapd.d/docker-openldap-was-started-with-tls"
5+ WAS_STARTED_WITH_REPLICATION=" /etc/ldap/slapd.d/docker-openldap-was-started-with-replication"
56
67# Reduce maximum number of number of open file descriptors to 1024
78# otherwise slapd consumes two orders of magnitude more of RAM
174175 echo " export PREVIOUS_SSL_KEY_FILENAME=${SSL_KEY_FILENAME} " >> $WAS_STARTED_WITH_TLS
175176 chmod +x $WAS_STARTED_WITH_TLS
176177
177- # add localhost route to certificate cn (need docker 1.5.0)
178- cn=$( openssl x509 -in /osixia/slapd/assets/ssl/$SSL_CRT_FILENAME -subject -noout | sed -n ' s/.*CN=\(.*\)\/*\(.*\)/\1/p' )
179- echo " 127.0.0.1 $cn " >> /etc/hosts
180-
181178 # local ldap tls client config
182179 sed -i " s,TLS_CACERT.*,TLS_CACERT /osixia/slapd/assets/ssl/${SSL_CA_CRT_FILENAME} ,g" /etc/ldap/ldap.conf
183180
@@ -194,135 +191,43 @@ EOF
194191 # replication config
195192 if [ " ${USE_REPLICATION,,} " == " true" ]; then
196193
197- echo " Set replication"
194+ echo " Use replication"
198195
199196 # copy template file
200197 cp /osixia/slapd/assets/config/replication/replication-enable-template.ldif /osixia/slapd/assets/config/replication/replication-enable.ldif
201198
202- function addReplicationSyncRepl() {
203-
204- local TYPE=$1
205- local HOST=$2
206- local INFOS=(${3} )
207-
208- olcSyncReplLine=" olcSyncRepl:"
209-
210- if [ " $TYPE " == " CONFIG" ]; then
211- olcSyncReplLine=" $olcSyncReplLine rid=00$i "
212- else
213- olcSyncReplLine=" $olcSyncReplLine rid=10$i "
214- fi
215-
216- olcSyncReplLine=" $olcSyncReplLine provider=$HOST "
217-
218- for info in " ${INFOS[@]} "
219- do
220-
221- info=($info )
222- local key_value_pair=(${! info[0]} )
223- local key=${! key_value_pair[0]}
224- local value=${! key_value_pair[1]}
225-
226- olcSyncReplLine=" $olcSyncReplLine $key =\" $value \" "
227-
228- done
229-
230- if [ " $TYPE " == " CONFIG" ]; then
231- sed -i " s|{{ REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|$olcSyncReplLine \n{{ REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|g" /osixia/slapd/assets/config/replication/replication-enable.ldif
232- else
233- sed -i " s|{{ REPLICATION_HOSTS_HDB_SYNC_REPL }}|$olcSyncReplLine \n{{ REPLICATION_HOSTS_HDB_SYNC_REPL }}|g" /osixia/slapd/assets/config/replication/replication-enable.ldif
234- fi
235- }
236-
237-
238- # replication hosts config
239- function addReplicationHost() {
240-
241- local HOST=$1
242- local INFOS=(${! 2} )
243-
244- local SERVER_ID_FOUND=false
245- local SYNCPROV_CONFIG_OBJECT_FOUND=false
246- local SYNCPROV_HDB_OBJECT_FOUND=false
247-
248- for info in " ${INFOS[@]} "
249- do
250- info=($info )
251- local key_value_pair=(${! info[0]} )
252- local key=${! key_value_pair[0]}
253- local value=${! key_value_pair[1]}
254-
255- # olcServerID
256- if [ " $key " == " server_id" ]; then
257- sed -i " s|{{ REPLICATION_HOSTS }}|olcServerID: $value $HOST \n{{ REPLICATION_HOSTS }}|g" /osixia/slapd/assets/config/replication/replication-enable.ldif
258- SERVER_ID_FOUND=true
259-
260- # olcSyncRepl for config and hdb
261- elif [ " $key " == " syncprov_config" ]; then
262- addReplicationSyncRepl CONFIG $HOST " $value "
263- SYNCPROV_CONFIG_OBJECT_FOUND=true
264-
265- elif [ " $key " == " syncprov_hdb" ]; then
266- addReplicationSyncRepl HDB $HOST " $value "
267- SYNCPROV_HDB_OBJECT_FOUND=true
268-
269- fi
270- done
271-
272- if ! $SERVER_ID_FOUND ; then
273- echo " Error: Replication host ${HOST} must define a server_id"
274- exit 1
275- fi
276-
277- if ! $SYNCPROV_CONFIG_OBJECT_FOUND ; then
278- echo " Error: Replication host ${HOST} must define a syncprov_config object"
279- exit 1
280- fi
281-
282- if ! $SYNCPROV_HDB_OBJECT_FOUND ; then
283- echo " Error: Replication host ${HOST} must define a syncprov_hdb object"
284- exit 1
285- fi
286- }
287-
288199 REPLICATION_HOSTS=($REPLICATION_HOSTS )
289200 i=1
290201 for host in " ${REPLICATION_HOSTS[@]} "
291202 do
292203
293204 # host var contain a variable name, we access to the variable value and cast it to a table
294- infos=( ${! host} )
205+ host= ${! host}
295206
296- # it's a table of infos
297- if [ " ${# infos[@]} " -gt " 1" ]; then
298-
299- addReplicationHost ${! infos[0]} ${infos[1]}
300-
301- else
302- echo " Error: Replication host ${! host} must define a server_id, syncprov_config and syncprov_hdb object"
303- exit 1
304- fi
207+ sed -i " s|{{ REPLICATION_HOSTS }}|olcServerID: $i ${host} \n{{ REPLICATION_HOSTS }}|g" /osixia/slapd/assets/config/replication/replication-enable.ldif
208+ sed -i " s|{{ REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|olcSyncRepl: rid=00$i provider=${host} ${REPLICATION_CONFIG_SYNCPROV} \n{{ REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|g" /osixia/slapd/assets/config/replication/replication-enable.ldif
209+ sed -i " s|{{ REPLICATION_HOSTS_HDB_SYNC_REPL }}|olcSyncRepl: rid=10$i provider=${host} ${REPLICATION_HDB_CONFIG} \n{{ REPLICATION_HOSTS_HDB_SYNC_REPL }}|g" /osixia/slapd/assets/config/replication/replication-enable.ldif
305210
306211 (( i++ ))
307212 done
308213
214+ get_base_dn
215+ sed -i " s|\$ BASE_DN|$BASE_DN |g" /osixia/slapd/assets/config/replication/replication-enable.ldif
216+ sed -i " s|\$ LDAP_ADMIN_PASSWORD|$LDAP_ADMIN_PASSWORD |g" /osixia/slapd/assets/config/replication/replication-enable.ldif
217+ sed -i " s|\$ LDAP_CONFIG_PASSWORD|$LDAP_CONFIG_PASSWORD |g" /osixia/slapd/assets/config/replication/replication-enable.ldif
309218
310219 sed -i " /{{ REPLICATION_HOSTS }}/d" /osixia/slapd/assets/config/replication/replication-enable.ldif
311220 sed -i " /{{ REPLICATION_HOSTS_CONFIG_SYNC_REPL }}/d" /osixia/slapd/assets/config/replication/replication-enable.ldif
312221 sed -i " /{{ REPLICATION_HOSTS_HDB_SYNC_REPL }}/d" /osixia/slapd/assets/config/replication/replication-enable.ldif
313222
314- cat /osixia/slapd/assets/config/replication/replication-enable.ldif
315- ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /osixia/slapd/assets/config/replication/replication-enable.ldif -v -d -1
223+ ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /osixia/slapd/assets/config/replication/replication-enable.ldif
224+ touch $WAS_STARTED_WITH_REPLICATION
316225
317226 else
318227
319- echo " Don't set replication"
320-
321- # disable replication
322- # for f in $(find /osixia/slapd/config/replication -name \*-disable.ldif -type f); do
323- # echo "Processing file ${f}"
324- # ldapmodify -Y EXTERNAL -Q -H ldapi:/// -f $f
325- # done
228+ echo " Don't use replication"
229+ [[ -f " $WAS_STARTED_WITH_REPLICATION " ]] && rm -f " $WAS_STARTED_WITH_REPLICATION "
230+ ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /osixia/slapd/assets/config/replication/replication-disable.ldif || true
326231
327232 fi
328233
0 commit comments