fix: handle first-time syncrepl configuration
All checks were successful
CI Pipeline / lint (push) Successful in 28s
CI Pipeline / build (push) Successful in 1m12s
CI Pipeline / test (push) Successful in 1m8s
CI Pipeline / security-scan (push) Successful in 1m38s
CI Pipeline / autotag (push) Successful in 24s
CI Pipeline / push (push) Successful in 21s
CI Pipeline / update-cd (push) Successful in 15s

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 d5405f3bba
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