Skip to content

Commit ea25220

Browse files
committed
replication
1 parent 8376919 commit ea25220

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

image/service/slapd/container-start.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,19 @@ EOF
104104

105105
# start OpenLDAP
106106
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 -d -1
118+
fi
119+
108120
echo "[ok]"
109121

110122
# set bootstrap config part 2
@@ -209,27 +221,23 @@ EOF
209221

210222
echo "Don't use TLS"
211223

212-
[[ -f "$WAS_STARTED_WITH_TLS" ]] && rm -f "$WAS_STARTED_WITH_TLS"
213224
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"
214226

215227
fi
216228

217229

218230
function disableReplication() {
219-
231+
echo "Try to disable replication if needed"
220232
ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-disable.ldif || true
221233
[[ -f "$WAS_STARTED_WITH_REPLICATION" ]] && rm -f "$WAS_STARTED_WITH_REPLICATION"
222-
223234
}
224235

225236
# replication config
226237
if [ "${LDAP_REPLICATION,,}" == "true" ]; then
227238

228239
echo "Use replication"
229-
230-
if [ -e "$WAS_STARTED_WITH_REPLICATION" ]; then
231-
disableReplication
232-
fi
240+
disableReplication || true
233241

234242
LDAP_REPLICATION_HOSTS=($LDAP_REPLICATION_HOSTS)
235243
i=1
@@ -255,9 +263,13 @@ EOF
255263
sed -i "/{{ LDAP_REPLICATION_HOSTS_CONFIG_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
256264
sed -i "/{{ LDAP_REPLICATION_HOSTS_HDB_SYNC_REPL }}/d" /container/service/slapd/assets/config/replication/replication-enable.ldif
257265

258-
ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-enable.ldif
259-
touch $WAS_STARTED_WITH_REPLICATION
266+
echo "Enable replication"
267+
ldapmodify -c -Y EXTERNAL -Q -H ldapi:/// -f /container/service/slapd/assets/config/replication/replication-enable.ldif || true
260268

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
261273

262274
else
263275

0 commit comments

Comments
 (0)