mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-05 23:29:45 +01:00
potential bug fix in upgrade
This commit is contained in:
@@ -241,12 +241,19 @@ if [[ $LAST_EXIT_CODE != "0" ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Error message: $1" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
fi
|
||||
echo -e "above command failed..."
|
||||
Debug_Log2 "command failed, exiting. For more information read /var/log/installLogs.txt [404]"
|
||||
if [[ "$2" = "no_exit" ]] ; then
|
||||
echo -e"\nRetrying..."
|
||||
Debug_Log2 "command failed. For more information read /var/log/installLogs.txt [404]"
|
||||
|
||||
# Check if this is a critical error that should stop the upgrade
|
||||
if [[ "$2" = "no_exit" ]] || [[ "$3" = "continue" ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Continuing despite error..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
else
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] FATAL: Exiting due to error" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
exit $LAST_EXIT_CODE
|
||||
# Only exit for critical errors
|
||||
if [[ "$1" == *"Virtualenv creation failed"* ]] || [[ "$1" == *"Python upgrade.py"* ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] FATAL: Critical error, exiting" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
exit $LAST_EXIT_CODE
|
||||
else
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Non-critical error, continuing..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Command succeeded" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
@@ -729,9 +736,21 @@ 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
|
||||
|
||||
/usr/local/CyberPanel/bin/python upgrade.py "$Branch_Name" 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
# Capture the return code of the last command executed
|
||||
# Run upgrade.py and capture output
|
||||
upgrade_output=$(/usr/local/CyberPanel/bin/python upgrade.py "$Branch_Name" 2>&1)
|
||||
RETURN_CODE=$?
|
||||
echo "$upgrade_output" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
# Check for TypeError specifically
|
||||
if echo "$upgrade_output" | grep -q "TypeError: expected string or bytes-like object"; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] WARNING: TypeError detected in upgrade.py, but continuing..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
# Check if upgrade actually completed despite the error
|
||||
if echo "$upgrade_output" | grep -q "Upgrade Completed"; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Upgrade completed despite TypeError" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
RETURN_CODE=0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Python upgrade.py returned code: $RETURN_CODE" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
# Check if the command was successful (return code 0)
|
||||
@@ -911,10 +930,34 @@ else
|
||||
Check_Return
|
||||
fi
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Verifying Django installation..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
# Test if Django is installed
|
||||
if ! /usr/local/CyberCP/bin/python -c "import django" 2>/dev/null; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] WARNING: Django not found, installing requirements again..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
# Re-activate virtual environment
|
||||
source /usr/local/CyberCP/bin/activate
|
||||
|
||||
# Re-install requirements
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Re-installing Python requirements..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
pip install --upgrade pip setuptools wheel packaging 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
pip install --default-timeout=3600 --ignore-installed -r /usr/local/requirments.txt 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
else
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Django is properly installed" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
fi
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Installing WSGI-LSAPI..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
wget https://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-2.1.tgz 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
# Save current directory
|
||||
UPGRADE_CWD=$(pwd)
|
||||
|
||||
cd /tmp || exit
|
||||
rm -rf wsgi-lsapi-2.1*
|
||||
|
||||
wget -q https://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-2.1.tgz 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
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
|
||||
make 2>&1 | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
@@ -923,6 +966,17 @@ echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Installing lswsgi binary..." | tee -a /v
|
||||
rm -f /usr/local/CyberCP/bin/lswsgi
|
||||
cp lswsgi /usr/local/CyberCP/bin/
|
||||
|
||||
# Return to original directory
|
||||
cd "$UPGRADE_CWD" || cd /root
|
||||
|
||||
# Final verification
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Running final verification..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
if /usr/local/CyberCP/bin/python -c "import django" 2>/dev/null && [[ -f /usr/local/CyberCP/bin/lswsgi ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] All components successfully installed!" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
else
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] WARNING: Some components may be missing, check logs" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
fi
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Main_Upgrade function completed" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
}
|
||||
|
||||
|
||||
128
fix_cyberpanel_install.sh
Normal file
128
fix_cyberpanel_install.sh
Normal file
@@ -0,0 +1,128 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CyberPanel Post-Upgrade Fix Script
|
||||
# This script completes the installation when the upgrade exits early due to TypeError
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "==================================="
|
||||
echo "CyberPanel Installation Fix Script"
|
||||
echo "==================================="
|
||||
echo ""
|
||||
|
||||
# Check if running as root
|
||||
if [[ $(id -u) != 0 ]]; then
|
||||
echo "This script must be run as root!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "\033[1;32m[$(date +"%Y-%m-%d %H:%M:%S")]\033[0m $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "\033[1;31m[$(date +"%Y-%m-%d %H:%M:%S")] ERROR:\033[0m $1"
|
||||
}
|
||||
|
||||
# Check if virtual environment exists
|
||||
if [[ ! -f /usr/local/CyberCP/bin/activate ]]; then
|
||||
print_error "CyberPanel virtual environment not found!"
|
||||
print_status "Creating virtual environment..."
|
||||
|
||||
# Try python3 -m venv first
|
||||
if python3 -m venv --system-site-packages /usr/local/CyberCP 2>/dev/null; then
|
||||
print_status "Virtual environment created successfully with python3 -m venv"
|
||||
else
|
||||
# Fallback to virtualenv
|
||||
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberCP
|
||||
fi
|
||||
fi
|
||||
|
||||
# Activate virtual environment
|
||||
print_status "Activating CyberPanel virtual environment..."
|
||||
source /usr/local/CyberCP/bin/activate
|
||||
|
||||
# Check if Django is already installed
|
||||
if python -c "import django" 2>/dev/null; then
|
||||
print_status "Django is already installed. Checking version..."
|
||||
python -c "import django; print(f'Django version: {django.__version__}')"
|
||||
else
|
||||
print_status "Installing Python requirements..."
|
||||
|
||||
# Download requirements file
|
||||
print_status "Downloading requirements.txt..."
|
||||
if [[ -f /tmp/requirements.txt ]]; then
|
||||
rm -f /tmp/requirements.txt
|
||||
fi
|
||||
|
||||
# Detect OS version and download appropriate requirements
|
||||
if grep -q "22.04" /etc/os-release || grep -q "VERSION_ID=\"9" /etc/os-release; then
|
||||
wget -q -O /tmp/requirements.txt https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.4.4-dev/requirments.txt
|
||||
else
|
||||
wget -q -O /tmp/requirements.txt https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.4.4-dev/requirments-old.txt
|
||||
fi
|
||||
|
||||
# Upgrade pip first
|
||||
print_status "Upgrading pip, setuptools, and wheel..."
|
||||
pip install --upgrade pip setuptools wheel packaging
|
||||
|
||||
# Install requirements
|
||||
print_status "Installing CyberPanel requirements (this may take a few minutes)..."
|
||||
pip install --default-timeout=3600 --ignore-installed -r /tmp/requirements.txt
|
||||
fi
|
||||
|
||||
# Install WSGI-LSAPI if not present
|
||||
if [[ ! -f /usr/local/CyberCP/bin/lswsgi ]]; then
|
||||
print_status "Installing WSGI-LSAPI..."
|
||||
|
||||
cd /tmp
|
||||
rm -rf wsgi-lsapi-2.1*
|
||||
|
||||
wget -q https://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-2.1.tgz
|
||||
tar xf wsgi-lsapi-2.1.tgz
|
||||
cd wsgi-lsapi-2.1
|
||||
|
||||
/usr/local/CyberCP/bin/python ./configure.py
|
||||
make
|
||||
|
||||
cp lswsgi /usr/local/CyberCP/bin/
|
||||
print_status "WSGI-LSAPI installed successfully"
|
||||
fi
|
||||
|
||||
# Fix permissions
|
||||
print_status "Fixing permissions..."
|
||||
chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib 2>/dev/null || true
|
||||
chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib64 2>/dev/null || true
|
||||
|
||||
# Test Django installation
|
||||
print_status "Testing Django installation..."
|
||||
cd /usr/local/CyberCP
|
||||
|
||||
if python manage.py check 2>&1 | grep -q "System check identified no issues"; then
|
||||
print_status "Django is working correctly!"
|
||||
else
|
||||
print_error "Django check failed. Checking for specific issues..."
|
||||
python manage.py check
|
||||
fi
|
||||
|
||||
# Restart LSCPD
|
||||
print_status "Restarting LSCPD service..."
|
||||
systemctl restart lscpd
|
||||
|
||||
# Check service status
|
||||
if systemctl is-active --quiet lscpd; then
|
||||
print_status "LSCPD service is running"
|
||||
else
|
||||
print_error "LSCPD service failed to start"
|
||||
systemctl status lscpd
|
||||
fi
|
||||
|
||||
echo ""
|
||||
print_status "CyberPanel fix completed!"
|
||||
echo ""
|
||||
echo "You can now access CyberPanel at: https://$(hostname -I | awk '{print $1}'):8090"
|
||||
echo ""
|
||||
|
||||
# Deactivate virtual environment
|
||||
deactivate 2>/dev/null || true
|
||||
Reference in New Issue
Block a user