diff --git a/scripts/ha/cluster-init.sh b/scripts/ha/cluster-init.sh index 9f1271b..6d850fd 100755 --- a/scripts/ha/cluster-init.sh +++ b/scripts/ha/cluster-init.sh @@ -186,9 +186,14 @@ log "Configuring LIO iSCSI target via targetcli..." # VIP resource will make the target reachable at the VIP address. # # Clear any existing LIO state first (idempotent: re-run after a partial failure). -if ls /sys/kernel/config/target/iscsi/ 2>/dev/null | grep -q iqn; then - log "Clearing existing LIO targets before reconfiguration..." - echo "clearconfig confirm=yes" | targetcli 2>/dev/null || true +# Use specific delete commands — clearconfig does not reliably clear kernel state. +if ls /sys/kernel/config/target/iscsi/ 2>/dev/null | grep -q "${ISCSI_IQN}"; then + log "Clearing existing LIO target ${ISCSI_IQN} before reconfiguration..." + targetcli "/iscsi delete ${ISCSI_IQN}" 2>/dev/null || true +fi +if ls /sys/kernel/config/target/core/ 2>/dev/null | grep -q "fileio"; then + log "Clearing existing LIO backstore ha-lun0 before reconfiguration..." + targetcli "/backstores/fileio delete ha-lun0" 2>/dev/null || true fi targetcli </dev/null || warn "LIO clearconfig had errors — umount may fail" +# Use specific delete commands (clearconfig does not reliably clear kernel configfs state). +targetcli "/iscsi delete ${ISCSI_IQN}" 2>/dev/null || warn "LIO iscsi delete failed — umount may fail" +targetcli "/backstores/fileio delete ha-lun0" 2>/dev/null || warn "LIO backstore delete failed" log "Distributing iSCSI saveconfig to $NODE2..." n2_scp /etc/target/saveconfig.json /etc/target/saveconfig.json @@ -210,7 +217,7 @@ log "Unmounting ${XFS_MOUNT} — Pacemaker manages it..." umount "${XFS_MOUNT}" || { sync; umount -l "${XFS_MOUNT}"; } log "Demoting DRBD to Secondary — Pacemaker manages primary role..." -drbdadm secondary ha-data +[[ "$(drbdadm role ha-data 2>/dev/null)" == "Primary/Secondary" ]] && drbdadm secondary ha-data || true # ── 7. Pacemaker resources ──────────────────────────────────────────────── log "Configuring Pacemaker cluster properties..."