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.
This commit is contained in:
Patrick de Ruiter 2025-12-28 01:00:33 +01:00
parent 11bead045f
commit 83bfbc7381
Signed by: pderuiter
GPG Key ID: 5EBA7F21CF583321

View File

@ -91,13 +91,30 @@ IFS="$OLD_IFS"
# Configure syncrepl and mirrormode on the database # Configure syncrepl and mirrormode on the database
log_info "Configuring syncrepl and mirrormode..." 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 cat > /tmp/repl-syncrepl.ldif << EOF
dn: olcDatabase={1}mdb,cn=config dn: olcDatabase={1}mdb,cn=config
changetype: modify changetype: modify
replace: olcSyncRepl ${SYNCREPL_OP}: olcSyncRepl
${SYNCREPL_CONFIG} ${SYNCREPL_CONFIG}
- -
replace: olcMirrorMode ${MIRRORMODE_OP}: olcMirrorMode
olcMirrorMode: TRUE olcMirrorMode: TRUE
EOF EOF