From d3472c03b42a45938f342bebfa60e796f10a4586 Mon Sep 17 00:00:00 2001 From: Seyed Mahdi <39972836+SeyedHashtag@users.noreply.github.com> Date: Fri, 5 Dec 2025 03:45:34 +0330 Subject: [PATCH] feat: improve upgrade process with lock file and background execution --- menu.sh | 38 ++++++++++++++++++++++++++++++++++++-- upgrade.sh | 19 ++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/menu.sh b/menu.sh index 23d0c0c5..78518ee8 100644 --- a/menu.sh +++ b/menu.sh @@ -396,7 +396,41 @@ edit_ips() { } hysteria_upgrade(){ - bash <(curl https://raw.githubusercontent.com/ReturnFI/Blitz/main/upgrade.sh) + # Check if upgrade is already running + if [ -f "/tmp/hysteria_upgrade.lock" ]; then + echo -e "${red}Error:${NC} An upgrade process is already running or was interrupted." + echo -e "${yellow}Please check the system status and remove /tmp/hysteria_upgrade.lock if needed.${NC}" + return 1 + fi + + # Create lock file to prevent concurrent upgrades + echo $$ > /tmp/hysteria_upgrade.lock + echo -e "${yellow}Upgrade process started. PID: $$${NC}" + + # Use nohup to continue running even if SSH disconnects + # Redirect output to log file for later inspection + nohup bash <(curl -s https://raw.githubusercontent.com/ReturnFI/Blitz/main/upgrade.sh) > /var/log/hysteria_upgrade.log 2>&1 & + + UPGRADE_PID=$! + echo -e "${green}Upgrade process started in background (PID: $UPGRADE_PID).${NC}" + echo -e "${yellow}You can safely disconnect. The upgrade will continue in the background.${NC}" + echo -e "${yellow}Check progress with: tail -f /var/log/hysteria_upgrade.log${NC}" + echo -e "${yellow}Or check status with: ps aux | grep upgrade.sh${NC}" + + # Wait a moment to let the process start + sleep 2 + + # Check if the process is still running + if ps -p $UPGRADE_PID > /dev/null; then + echo -e "${green}Upgrade process is running successfully in the background.${NC}" + else + echo -e "${red}Error:${NC} Upgrade process failed to start." + rm -f /tmp/hysteria_upgrade.lock + return 1 + fi + + # Remove lock file when done (this will be handled by the upgrade script) + # The upgrade script should remove the lock file when completed } warp_configure_handler() { @@ -1216,4 +1250,4 @@ advance_menu() { } # Main function to run the script define_colors -main_menu \ No newline at end of file +main_menu diff --git a/upgrade.sh b/upgrade.sh index 0954f545..32e5b617 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -189,6 +189,17 @@ for SERVICE in "${ALL_SERVICES[@]}"; do fi done +# ========== Check for existing upgrade process ========== +if [ -f "/tmp/hysteria_upgrade.lock" ]; then + info "Found existing upgrade lock file. This might be from a previous interrupted upgrade." + info "Removing lock file to allow this upgrade to proceed..." + rm -f /tmp/hysteria_upgrade.lock +fi + +# ========== Create new lock file ========== +echo $$ > /tmp/hysteria_upgrade.lock +info "Upgrade process started. PID: $$" + # ========== Check AVX Support Prerequisite ========== check_avx_support @@ -333,4 +344,10 @@ fi info "Upgrade process finished. Launching menu..." cd "$HYSTERIA_INSTALL_DIR" chmod +x menu.sh -./menu.sh \ No newline at end of file + +# ========== Cleanup ========== +info "Cleaning up upgrade lock file..." +rm -f /tmp/hysteria_upgrade.lock +success "Upgrade lock file removed." + +./menu.sh