|
104 | 104 |
|
105 | 105 | # start OpenLDAP |
106 | 106 | echo "Starting openldap..." |
107 | | - slapd -h "ldap://$HOSTNAME ldap://localhost ldapi:///" -u openldap -g openldap |
| 107 | + |
| 108 | + # start OpenLDAP with previous replication configuration |
| 109 | + if [ -e "$WAS_STARTED_WITH_REPLICATION" ]; then |
| 110 | + |
| 111 | + . $WAS_STARTED_WITH_REPLICATION |
| 112 | + echo "127.0.0.2 $PREVIOUS_HOSTNAME" >> /etc/hosts |
| 113 | + |
| 114 | + slapd -h "ldap://$HOSTNAME ldap://$PREVIOUS_HOSTNAME ldap://localhost ldapi:///" -u openldap -g openldap |
| 115 | + else |
| 116 | + #start openldap normaly |
| 117 | + slapd -h "ldap://$HOSTNAME ldap://localhost ldapi:///" -u openldap -g openldap |
| 118 | + fi |
| 119 | + |
108 | 120 | echo "[ok]" |
109 | 121 |
|
110 | 122 | # set bootstrap config part 2 |
@@ -209,55 +221,60 @@ EOF |
209 | 221 |
|
210 | 222 | echo "Don't use TLS" |
211 | 223 |
|
212 | | - [[ -f "$WAS_STARTED_WITH_TLS" ]] && rm -f "$WAS_STARTED_WITH_TLS" |
213 | 224 | ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/tls/tls-disable.ldif || true |
| 225 | + [[ -f "$WAS_STARTED_WITH_TLS" ]] && rm -f "$WAS_STARTED_WITH_TLS" |
214 | 226 |
|
215 | 227 | fi |
216 | 228 |
|
217 | 229 |
|
| 230 | + function disableReplication() { |
| 231 | + echo "Try to disable replication if needed" |
| 232 | + ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-disable.ldif || true |
| 233 | + [[ -f "$WAS_STARTED_WITH_REPLICATION" ]] && rm -f "$WAS_STARTED_WITH_REPLICATION" |
| 234 | + } |
| 235 | + |
218 | 236 | # replication config |
219 | 237 | if [ "${LDAP_REPLICATION,,}" == "true" ]; then |
220 | 238 |
|
221 | | - if [ -e "$WAS_STARTED_WITH_REPLICATION" ]; then |
222 | | - echo "Replication already set" |
223 | | - else |
224 | | - echo "Use replication" |
| 239 | + echo "Use replication" |
| 240 | + disableReplication || true |
225 | 241 |
|
226 | | - LDAP_REPLICATION_HOSTS=($LDAP_REPLICATION_HOSTS) |
227 | | - i=1 |
228 | | - for host in "${LDAP_REPLICATION_HOSTS[@]}" |
229 | | - do |
| 242 | + LDAP_REPLICATION_HOSTS=($LDAP_REPLICATION_HOSTS) |
| 243 | + i=1 |
| 244 | + for host in "${LDAP_REPLICATION_HOSTS[@]}" |
| 245 | + do |
230 | 246 |
|
231 | | - # host var contain a variable name, we access to the variable value |
232 | | - host=${!host} |
| 247 | + # host var contain a variable name, we access to the variable value |
| 248 | + host=${!host} |
233 | 249 |
|
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 |
| 250 | + sed -i "s|{{ LDAP_REPLICATION_HOSTS }}|olcServerID: $i ${host}\n{{ LDAP_REPLICATION_HOSTS }}|g" /container/service/slapd/assets/config/replication/replication-enable.ldif |
| 251 | + 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 |
| 252 | + 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 |
237 | 253 |
|
238 | | - ((i++)) |
239 | | - done |
| 254 | + ((i++)) |
| 255 | + done |
240 | 256 |
|
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 |
| 257 | + get_ldap_base_dn |
| 258 | + sed -i "s|\$LDAP_BASE_DN|$LDAP_BASE_DN|g" /container/service/slapd/assets/config/replication/replication-enable.ldif |
| 259 | + sed -i "s|\$LDAP_ADMIN_PASSWORD|$LDAP_ADMIN_PASSWORD|g" /container/service/slapd/assets/config/replication/replication-enable.ldif |
| 260 | + sed -i "s|\$LDAP_CONFIG_PASSWORD|$LDAP_CONFIG_PASSWORD|g" /container/service/slapd/assets/config/replication/replication-enable.ldif |
245 | 261 |
|
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 |
| 262 | + sed -i "/{{ LDAP_REPLICATION_HOSTS }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif |
| 263 | + sed -i "/{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif |
| 264 | + sed -i "/{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif |
249 | 265 |
|
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 |
| 266 | + echo "Enable replication" |
| 267 | + ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-enable.ldif || true |
| 268 | + |
| 269 | + [[ -f "$WAS_STARTED_WITH_REPLICATION" ]] && rm -f "$WAS_STARTED_WITH_REPLICATION" |
| 270 | + touch $WAS_STARTED_WITH_REPLICATION |
| 271 | + echo "export PREVIOUS_HOSTNAME=${HOSTNAME}" >> $WAS_STARTED_WITH_REPLICATION |
| 272 | + chmod +x $WAS_STARTED_WITH_REPLICATION |
253 | 273 |
|
254 | 274 | else |
255 | 275 |
|
256 | 276 | 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 |
| 277 | + disableReplication || true |
261 | 278 |
|
262 | 279 | fi |
263 | 280 |
|
|
0 commit comments