From d5405f3bbaacf27bb0a26b5cde6902ce75714326 Mon Sep 17 00:00:00 2001 From: Patrick de Ruiter Date: Sun, 28 Dec 2025 01:00:33 +0100 Subject: [PATCH] fix: handle first-time syncrepl configuration Check if olcSyncRepl and olcMirrorMode attributes exist before deciding whether to use 'add' or 'replace' operation. Previously the script always used 'replace' which fails on first-time setup when the attributes don't exist yet. --- scripts/init-replication.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/init-replication.sh b/scripts/init-replication.sh index 6c4dbc4..95aeb54 100755 --- a/scripts/init-replication.sh +++ b/scripts/init-replication.sh @@ -91,13 +91,30 @@ IFS="$OLD_IFS" # Configure syncrepl and mirrormode on the database log_info "Configuring syncrepl and mirrormode..." + +# Check if olcSyncRepl attribute already exists +if ldapsearch -Y EXTERNAL -H "$LDAPI_SOCKET" -b "olcDatabase={1}mdb,cn=config" -s base "(olcSyncRepl=*)" olcSyncRepl 2>/dev/null | grep -q "olcSyncRepl:"; then + SYNCREPL_OP="replace" + log_info "Updating existing syncrepl configuration..." +else + SYNCREPL_OP="add" + log_info "Adding new syncrepl configuration..." +fi + +# Check if olcMirrorMode attribute already exists +if ldapsearch -Y EXTERNAL -H "$LDAPI_SOCKET" -b "olcDatabase={1}mdb,cn=config" -s base "(olcMirrorMode=*)" olcMirrorMode 2>/dev/null | grep -q "olcMirrorMode:"; then + MIRRORMODE_OP="replace" +else + MIRRORMODE_OP="add" +fi + cat > /tmp/repl-syncrepl.ldif << EOF dn: olcDatabase={1}mdb,cn=config changetype: modify -replace: olcSyncRepl +${SYNCREPL_OP}: olcSyncRepl ${SYNCREPL_CONFIG} - -replace: olcMirrorMode +${MIRRORMODE_OP}: olcMirrorMode olcMirrorMode: TRUE EOF