@@ -527,16 +527,14 @@ patch_dappmanager_compose_for_macos() {
527527}
528528
529529bootstrap_filesystem () {
530- # Clean if update
530+ # Clean if update — only the logfile and profile are removed here.
531+ # Removing the profile early forces ensure_profile_loaded to re-download
532+ # the latest one (so resolved package versions match the new release).
533+ # Composes/manifests/archives are removed later by clean_for_update,
534+ # AFTER preflight passes — see comment in main().
531535 if [[ " ${UPDATE} " == " true" ]]; then
532- log " Cleaning for update..."
533536 rm -f " ${LOGFILE} " || true
534- rm -f " ${DAPPNODE_CORE_DIR} " /docker-compose-* .yml || true
535- rm -f " ${DAPPNODE_CORE_DIR} " /dappnode_package-* .json || true
536- rm -f " ${DAPPNODE_CORE_DIR} " /* .tar.xz || true
537- rm -f " ${DAPPNODE_CORE_DIR} " /* .txz || true
538537 rm -f " ${DAPPNODE_CORE_DIR} /.dappnode_profile" || true
539- rm -f " ${CONTENT_HASH_FILE} " || true
540538 fi
541539
542540 # Create necessary directories
@@ -551,6 +549,22 @@ bootstrap_filesystem() {
551549 touch " ${LOGFILE} " || true
552550}
553551
552+ # Destructive: remove on-disk artifacts from the previous install so fresh
553+ # downloads take their place. Must only run AFTER preflight checks have passed —
554+ # otherwise a failing preflight (e.g. port conflict) leaves the host with no
555+ # compose files on disk while running containers continue to hold the ports.
556+ clean_for_update () {
557+ if [[ " ${UPDATE} " != " true" ]]; then
558+ return 0
559+ fi
560+ log " Cleaning for update..."
561+ rm -f " ${DAPPNODE_CORE_DIR} " /docker-compose-* .yml || true
562+ rm -f " ${DAPPNODE_CORE_DIR} " /dappnode_package-* .json || true
563+ rm -f " ${DAPPNODE_CORE_DIR} " /* .tar.xz || true
564+ rm -f " ${DAPPNODE_CORE_DIR} " /* .txz || true
565+ rm -f " ${CONTENT_HASH_FILE} " || true
566+ }
567+
554568# Generic helper: returns 0 if a process is bound to the given port, 1 if not.
555569# Usage: is_port_listening <port> [tcp|udp]
556570# tcp (default): matches TCP sockets in LISTEN state
@@ -1107,6 +1121,10 @@ main() {
11071121 configure_static_ip
11081122 ensure_profile_loaded
11091123 resolve_packages
1124+ # Destructive cleanup runs only after preflight (resolve_packages -> check_vpn_ports_conflict)
1125+ # has passed; otherwise a failing port check would wipe the on-disk composes while the
1126+ # running containers still hold the ports, leaving the node un-restartable.
1127+ clean_for_update
11101128
11111129 echo " " 2>&1 | tee -a " $LOGFILE "
11121130 log " ##############################################"
0 commit comments