@@ -215,49 +215,56 @@ EOF
215215 fi
216216
217217
218+ function disableReplication() {
219+
220+ ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-disable.ldif || true
221+ [[ -f " $WAS_STARTED_WITH_REPLICATION " ]] && rm -f " $WAS_STARTED_WITH_REPLICATION "
222+
223+ }
224+
218225 # replication config
219226 if [ " ${LDAP_REPLICATION,,} " == " true" ]; then
220227
228+ echo " Use replication"
229+
221230 if [ -e " $WAS_STARTED_WITH_REPLICATION " ]; then
222- echo " Replication already set"
223- else
224- echo " Use replication"
231+ disableReplication
232+ fi
225233
226- LDAP_REPLICATION_HOSTS=($LDAP_REPLICATION_HOSTS )
227- i=1
228- for host in " ${LDAP_REPLICATION_HOSTS[@]} "
229- do
230234
231- # host var contain a variable name, we access to the variable value
232- host=${! host}
233235
234- sed -i " s|{{ LDAP_REPLICATION_HOSTS }}|olcServerID: $i ${host} \n{{ LDAP_REPLICATION_HOSTS }}|g" /container/service/slapd/assets/config/replication/replication-enable.ldif
235- sed -i " s|{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|olcSyncRepl: rid=00$i provider=${host} ${LDAP_REPLICATION_CONFIG_SYNCPROV} \n{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|g" /container/service/slapd/assets/config/replication/replication-enable.ldif
236- sed -i " s|{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}|olcSyncRepl: rid=10$i provider=${host} ${LDAP_REPLICATION_HDB_SYNCPROV} \n{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}|g" /container/service/slapd/assets/config/replication/replication-enable.ldif
236+ LDAP_REPLICATION_HOSTS=($LDAP_REPLICATION_HOSTS )
237+ i=1
238+ for host in " ${LDAP_REPLICATION_HOSTS[@]} "
239+ do
237240
238- (( i ++ ))
239- done
241+ # host var contain a variable name, we access to the variable value
242+ host= ${ ! host}
240243
241- get_ldap_base_dn
242- sed -i " s|\$ LDAP_BASE_DN|$LDAP_BASE_DN |g" /container/service/slapd/assets/config/replication/replication-enable.ldif
243- sed -i " s|\$ LDAP_ADMIN_PASSWORD|$LDAP_ADMIN_PASSWORD |g" /container/service/slapd/assets/config/replication/replication-enable.ldif
244- sed -i " s|\$ LDAP_CONFIG_PASSWORD|$LDAP_CONFIG_PASSWORD |g" /container/service/slapd/assets/config/replication/replication-enable.ldif
244+ sed -i " s|{{ LDAP_REPLICATION_HOSTS }}|olcServerID: $i ${host} \n{{ LDAP_REPLICATION_HOSTS }}|g" /container/service/slapd/assets/config/replication/replication-enable.ldif
245+ sed -i " s|{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|olcSyncRepl: rid=00$i provider=${host} ${LDAP_REPLICATION_CONFIG_SYNCPROV} \n{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}|g" /container/service/slapd/assets/config/replication/replication-enable.ldif
246+ sed -i " s|{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}|olcSyncRepl: rid=10$i provider=${host} ${LDAP_REPLICATION_HDB_SYNCPROV} \n{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}|g" /container/service/slapd/assets/config/replication/replication-enable.ldif
245247
246- sed -i " /{{ LDAP_REPLICATION_HOSTS }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
247- sed -i " /{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
248- sed -i " /{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
248+ (( i++ ))
249+ done
250+
251+ get_ldap_base_dn
252+ sed -i " s|\$ LDAP_BASE_DN|$LDAP_BASE_DN |g" /container/service/slapd/assets/config/replication/replication-enable.ldif
253+ sed -i " s|\$ LDAP_ADMIN_PASSWORD|$LDAP_ADMIN_PASSWORD |g" /container/service/slapd/assets/config/replication/replication-enable.ldif
254+ sed -i " s|\$ LDAP_CONFIG_PASSWORD|$LDAP_CONFIG_PASSWORD |g" /container/service/slapd/assets/config/replication/replication-enable.ldif
255+
256+ sed -i " /{{ LDAP_REPLICATION_HOSTS }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
257+ sed -i " /{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
258+ sed -i " /{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
259+
260+ ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-enable.ldif
261+ touch $WAS_STARTED_WITH_REPLICATION
249262
250- ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-enable.ldif
251- touch $WAS_STARTED_WITH_REPLICATION
252- fi
253263
254264 else
255265
256266 echo " Don't use replication"
257- [[ -f " $WAS_STARTED_WITH_REPLICATION " ]] && rm -f " $WAS_STARTED_WITH_REPLICATION "
258- ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-disable.ldif || true
259-
260- rm -f $WAS_STARTED_WITH_REPLICATION
267+ disableReplication
261268
262269 fi
263270
0 commit comments