From 7cab70dbaf55466dd83a8d9d6066e30cf13fcf4e Mon Sep 17 00:00:00 2001 From: master3395 Date: Wed, 4 Feb 2026 22:46:48 +0100 Subject: [PATCH] Resolve /usr/local/CyberPanel/bin/python on install, upgrade, downgrade Install: - install.py: in preFlightsChecks.call(), replace missing CyberPanel python with /usr/bin/python3 and force shell=True so any code path (including old/cached script) never hits FileNotFoundError. Upgrade: - cyberpanel_upgrade.sh: resolve CP_PYTHON (CyberPanel, CyberCP, python3) before running upgrade.py and configure.py; use it for both. - plogical/upgrade.py: add _python_for_manage(), use it in GeneralMigrations, collectstatic, and upgradePip so migrations/collectstatic work when /usr/local/CyberPanel/bin/python is missing. --- cyberpanel_upgrade.sh | 19 ++++++++++++++++--- install/install.py | 7 +++++++ plogical/upgrade.py | 35 +++++++++++++++-------------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/cyberpanel_upgrade.sh b/cyberpanel_upgrade.sh index 601854724..90e545fb8 100644 --- a/cyberpanel_upgrade.sh +++ b/cyberpanel_upgrade.sh @@ -947,10 +947,21 @@ Pre_Upgrade_Branch_Input() { Main_Upgrade() { echo -e "\n[$(date +"%Y-%m-%d %H:%M:%S")] Starting Main_Upgrade function..." | tee -a /var/log/cyberpanel_upgrade_debug.log -echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Running: /usr/local/CyberPanel/bin/python upgrade.py $Branch_Name" | tee -a /var/log/cyberpanel_upgrade_debug.log + +# Resolve Python for upgrade (avoid FileNotFoundError when /usr/local/CyberPanel/bin/python missing) +CP_PYTHON="" +for py in /usr/local/CyberPanel/bin/python /usr/local/CyberCP/bin/python /usr/bin/python3 /usr/local/bin/python3; do + if [[ -x "$py" ]]; then CP_PYTHON="$py"; break; fi +done +if [[ -z "$CP_PYTHON" ]]; then + echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] ERROR: No Python found for upgrade (tried CyberPanel, CyberCP, python3)" | tee -a /var/log/cyberpanel_upgrade_debug.log + exit 1 +fi +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Using Python: $CP_PYTHON" | tee -a /var/log/cyberpanel_upgrade_debug.log +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Running: $CP_PYTHON upgrade.py $Branch_Name" | tee -a /var/log/cyberpanel_upgrade_debug.log # Run upgrade.py and capture output -upgrade_output=$(/usr/local/CyberPanel/bin/python upgrade.py "$Branch_Name" 2>&1) +upgrade_output=$("$CP_PYTHON" upgrade.py "$Branch_Name" 2>&1) RETURN_CODE=$? echo "$upgrade_output" | tee -a /var/log/cyberpanel_upgrade_debug.log @@ -1217,7 +1228,9 @@ tar xf wsgi-lsapi-2.1.tgz cd wsgi-lsapi-2.1 || exit echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Configuring WSGI..." | tee -a /var/log/cyberpanel_upgrade_debug.log -/usr/local/CyberPanel/bin/python ./configure.py 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log +PYTHON_CFG="${CP_PYTHON:-/usr/bin/python3}" +[[ -x "$PYTHON_CFG" ]] || PYTHON_CFG="/usr/bin/python3" +"$PYTHON_CFG" ./configure.py 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log # Fix Makefile to use proper optimization flags to avoid _FORTIFY_SOURCE warnings echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Optimizing Makefile for proper compilation..." | tee -a /var/log/cyberpanel_upgrade_debug.log diff --git a/install/install.py b/install/install.py index c087e2f8a..6dba4cce1 100644 --- a/install/install.py +++ b/install/install.py @@ -2839,6 +2839,13 @@ module cyberpanel_ols { # Using shared function from install_utils @staticmethod def call(command, distro, bracket, message, log=0, do_exit=0, code=os.EX_OK, shell=False): + # Fix missing /usr/local/CyberPanel/bin/python on install/upgrade (avoid FileNotFoundError) + if isinstance(command, str) and '/usr/local/CyberPanel/bin/python' in command: + if not os.path.isfile('/usr/local/CyberPanel/bin/python'): + fallback = '/usr/bin/python3' if os.path.isfile('/usr/bin/python3') else '/usr/local/bin/python3' + if os.path.isfile(fallback): + command = command.replace('/usr/local/CyberPanel/bin/python', fallback, 1) + shell = True return install_utils.call(command, distro, bracket, message, log, do_exit, code, shell) def checkIfSeLinuxDisabled(self): diff --git a/plogical/upgrade.py b/plogical/upgrade.py index f96dabe12..5bd9deac8 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -1715,8 +1715,8 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout'; cwd = os.getcwd() os.chdir('/usr/local/CyberCP') - - command = '/usr/local/CyberPanel/bin/python manage.py collectstatic --noinput --clear' + py = Upgrade._python_for_manage() + command = py + ' manage.py collectstatic --noinput --clear' Upgrade.executioner(command, 'Remove old static content', 0) os.chdir(cwd) @@ -3084,18 +3084,27 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL except: pass + @staticmethod + def _python_for_manage(): + """Resolve Python for manage.py (avoid FileNotFoundError when /usr/local/CyberPanel/bin/python missing).""" + for path in ('/usr/local/CyberPanel/bin/python', '/usr/local/CyberCP/bin/python', '/usr/bin/python3', '/usr/local/bin/python3'): + if path and os.path.isfile(path) and os.access(path, os.X_OK): + return path + return '/usr/bin/python3' + @staticmethod def GeneralMigrations(): try: cwd = os.getcwd() os.chdir('/usr/local/CyberCP') + py = Upgrade._python_for_manage() - command = '/usr/local/CyberPanel/bin/python manage.py makemigrations' + command = py + ' manage.py makemigrations' Upgrade.executioner(command, 'python manage.py makemigrations', 0) - command = '/usr/local/CyberPanel/bin/python manage.py makemigrations' - Upgrade.executioner(command, '/usr/local/CyberPanel/bin/python manage.py migrate', 0) + command = py + ' manage.py makemigrations' + Upgrade.executioner(command, py + ' manage.py migrate', 0) os.chdir(cwd) @@ -4606,21 +4615,7 @@ echo $oConfig->Save() ? 'Done' : 'Error'; """Upgrade pip to latest version for better package compatibility""" try: Upgrade.stdOut("Upgrading pip to latest version...", 1) - - # Determine the correct Python path - python_paths = [ - "/usr/local/CyberPanel/bin/python", - "/usr/local/CyberCP/bin/python", - "/usr/bin/python3", - "/usr/local/bin/python3" - ] - - python_path = None - for path in python_paths: - if os.path.exists(path): - python_path = path - break - + python_path = Upgrade._python_for_manage() if not python_path: Upgrade.stdOut("No Python executable found for pip upgrade", 0) return False