From 7f5f4045b5c0eeb4fceb4d9075099fbd9e7061c2 Mon Sep 17 00:00:00 2001 From: Master3395 Date: Thu, 25 Sep 2025 20:27:16 +0200 Subject: [PATCH] Add post-installation fixes and verification to CyberPanel installation script - Introduced a new function to address common post-installation issues, including starting services and fixing database permissions. - Added a verification function to ensure services are running and accessible after installation. - Implemented checks for MariaDB and LiteSpeed services, along with database connection validation. - Enhanced user feedback during the installation process with detailed status messages and troubleshooting steps. --- INSTALLER_SUMMARY.md | 2 +- README_MODULAR.md | 140 ---------------------------------- cyberpanel.sh | 177 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 174 insertions(+), 145 deletions(-) delete mode 100644 README_MODULAR.md diff --git a/INSTALLER_SUMMARY.md b/INSTALLER_SUMMARY.md index 28bedcfc0..458f6e0a3 100644 --- a/INSTALLER_SUMMARY.md +++ b/INSTALLER_SUMMARY.md @@ -138,7 +138,7 @@ The installer is now ready and will provide the **best CyberPanel installation e When users run: ```bash -bash <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.5.5-dev/cyberpanel.sh) --debug +bash <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/cyberpanel.sh) --debug ``` They'll get: diff --git a/README_MODULAR.md b/README_MODULAR.md deleted file mode 100644 index f8f15aee2..000000000 --- a/README_MODULAR.md +++ /dev/null @@ -1,140 +0,0 @@ -# CyberPanel Modular Installer - -This is an enhanced, modular version of the CyberPanel installer that organizes code into manageable modules, each under 500 lines for better maintainability and updates. - -## 📁 Module Structure - -``` -cyberpanel/ -├── install.sh # Main installer script -├── modules/ -│ ├── os/ -│ │ └── detect.sh # OS detection module (~200 lines) -│ ├── deps/ -│ │ ├── manager.sh # Dependency manager coordinator (~150 lines) -│ │ ├── rhel_deps.sh # RHEL-based OS dependencies (~300 lines) -│ │ └── debian_deps.sh # Debian-based OS dependencies (~250 lines) -│ ├── install/ -│ │ └── cyberpanel_installer.sh # CyberPanel installation logic (~400 lines) -│ └── fixes/ -│ └── cyberpanel_fixes.sh # Common fixes and repairs (~450 lines) -└── README_MODULAR.md # This documentation -``` - -## 🚀 Usage - -### Basic Installation -```bash -bash install.sh -``` - -### Installation with Specific Branch -```bash -bash install.sh -b v2.5.5-dev -``` - -### Installation with Debug Mode -```bash -bash install.sh --debug -``` - -### Installation with Commit Hash -```bash -bash install.sh -b commit:abc1234 -``` - -## 🔧 Module Details - -### OS Detection Module (`modules/os/detect.sh`) -- Detects operating system and architecture -- Identifies package manager (yum, dnf, apt) -- Installs basic tools (curl, wget) -- Supports: CentOS, AlmaLinux, Rocky Linux, RHEL, CloudLinux, Ubuntu, Debian, openEuler - -### Dependency Management (`modules/deps/`) -- **manager.sh**: Coordinates dependency installation -- **rhel_deps.sh**: Handles RHEL-based OS dependencies -- **debian_deps.sh**: Handles Debian-based OS dependencies -- Installs development tools, core packages, and OS-specific requirements - -### Installation Logic (`modules/install/cyberpanel_installer.sh`) -- Handles CyberPanel installation process -- Supports fresh install, update, and reinstall -- Includes retry logic (up to 5 attempts) -- Manages different installation types - -### Fixes Module (`modules/fixes/cyberpanel_fixes.sh`) -- Fixes common installation issues -- Database connection fixes -- Service configuration fixes -- SSL certificate generation -- File permission fixes -- Status checking and reporting - -## 🎯 Benefits of Modular Architecture - -1. **Maintainability**: Each module is under 500 lines, making it easy to understand and modify -2. **Modularity**: Changes to one OS don't affect others -3. **Debugging**: Easier to isolate and fix issues -4. **Updates**: Can update individual modules without touching others -5. **Testing**: Each module can be tested independently -6. **Documentation**: Clear separation of concerns - -## 🔄 Update Process - -To update specific functionality: - -1. **OS Support**: Modify `modules/os/detect.sh` -2. **Dependencies**: Update `modules/deps/rhel_deps.sh` or `modules/deps/debian_deps.sh` -3. **Installation Logic**: Modify `modules/install/cyberpanel_installer.sh` -4. **Fixes**: Update `modules/fixes/cyberpanel_fixes.sh` - -## 🐛 Troubleshooting - -### Module Loading Issues -If a module fails to load, check: -- File permissions (should be executable) -- File path (relative to install.sh) -- Syntax errors in the module - -### Dependency Issues -- Check the specific OS module in `modules/deps/` -- Verify package manager commands -- Check for missing repositories - -### Installation Issues -- Review the installation module logs -- Check retry attempts in the installer -- Verify CyberPanel source availability - -## 📝 Logging - -All modules log to `/var/log/cyberpanel_install.log` with timestamps and module identification. - -## 🔧 Customization - -To add support for a new OS: - -1. Add detection logic to `modules/os/detect.sh` -2. Create a new dependency module in `modules/deps/` -3. Update the dependency manager to handle the new OS -4. Test thoroughly - -## 📊 Status Reporting - -The installer provides comprehensive status reporting including: -- Service status (running, enabled, disabled) -- Port status (listening, not listening) -- Database connectivity -- File system checks -- Resource usage - -## 🎉 Success Criteria - -A successful installation should show: -- ✅ All critical services running -- ✅ All required ports listening -- ✅ Database connections working -- ✅ No critical failures - -This modular approach makes the CyberPanel installer much more maintainable and easier to extend for new operating systems and features. diff --git a/cyberpanel.sh b/cyberpanel.sh index 485084c56..fa98a0ae0 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -140,6 +140,148 @@ detect_os() { return 0 } +# Function to fix post-installation issues +fix_post_install_issues() { + echo " 🔧 Fixing database connection issues..." + + # Wait for services to start + sleep 10 + + # Start and enable MariaDB if not running + if ! systemctl is-active --quiet mariadb; then + echo " Starting MariaDB service..." + systemctl start mariadb + systemctl enable mariadb + sleep 5 + fi + + # Start and enable LiteSpeed if not running + if ! systemctl is-active --quiet lsws; then + echo " Starting LiteSpeed service..." + systemctl start lsws + systemctl enable lsws + sleep 5 + fi + + # Fix database user permissions + echo " Fixing database user permissions..." + + # Wait for MariaDB to be ready + local retry_count=0 + while [ $retry_count -lt 10 ]; do + if mysql -e "SELECT 1;" >/dev/null 2>&1; then + break + fi + echo " Waiting for MariaDB to be ready... ($((retry_count + 1))/10)" + sleep 2 + retry_count=$((retry_count + 1)) + done + + # Create database user with proper permissions + mysql -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true + mysql -e "CREATE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true + mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true + mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true + + # Create CyberPanel database if it doesn't exist + mysql -e "CREATE DATABASE IF NOT EXISTS cyberpanel;" 2>/dev/null || true + mysql -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost';" 2>/dev/null || true + mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true + + # Reset CyberPanel admin password + echo " Resetting CyberPanel admin password..." + /usr/local/CyberCP/bin/python3 /usr/local/CyberCP/plogical/adminPass.py 2>/dev/null || true + + # Fix PHP configuration files + echo " Fixing PHP configuration..." + for php_version in lsphp72 lsphp73 lsphp74 lsphp80 lsphp81 lsphp82 lsphp83 lsphp84; do + if [ -d "/usr/local/lsws/$php_version" ]; then + # Create missing php.ini if it doesn't exist + if [ ! -f "/usr/local/lsws/$php_version/etc/php.ini" ]; then + echo " Creating missing php.ini for $php_version..." + cp /usr/local/lsws/lsphp82/etc/php.ini "/usr/local/lsws/$php_version/etc/php.ini" 2>/dev/null || true + fi + fi + done + + # Restart services + echo " Restarting services..." + systemctl restart mariadb + systemctl restart lsws + + # Wait for services to stabilize + sleep 10 + + # Verify services are running + if systemctl is-active --quiet mariadb && systemctl is-active --quiet lsws; then + echo " ✅ Post-installation fixes completed successfully" + + # Run final verification + verify_installation + else + echo " ⚠️ Some services may need manual attention" + echo " 🔧 Attempting additional fixes..." + + # Additional service fixes + systemctl daemon-reload + systemctl reset-failed mariadb lsws + systemctl start mariadb lsws + + sleep 5 + verify_installation + fi +} + +# Function to verify installation +verify_installation() { + echo "" + echo " 🔍 Verifying installation..." + + local issues=0 + + # Check MariaDB + if systemctl is-active --quiet mariadb; then + echo " ✅ MariaDB is running" + else + echo " ❌ MariaDB is not running" + issues=$((issues + 1)) + fi + + # Check LiteSpeed + if systemctl is-active --quiet lsws; then + echo " ✅ LiteSpeed is running" + else + echo " ❌ LiteSpeed is not running" + issues=$((issues + 1)) + fi + + # Check web interface + if curl -s -k --connect-timeout 5 https://localhost:8090 >/dev/null 2>&1; then + echo " ✅ Web interface is accessible" + else + echo " ⚠️ Web interface may not be accessible yet (this is normal)" + fi + + # Check database connection + if mysql -e "SELECT 1;" >/dev/null 2>&1; then + echo " ✅ Database connection is working" + else + echo " ❌ Database connection failed" + issues=$((issues + 1)) + fi + + if [ $issues -eq 0 ]; then + echo "" + echo " 🎉 Installation verification completed successfully!" + echo " 🌐 You can now access CyberPanel at: https://$(curl -s ifconfig.me):8090" + else + echo "" + echo " ⚠️ Installation completed with $issues issue(s)" + echo " 🔧 Some manual intervention may be required" + echo " 📋 Check the logs at: /var/log/CyberPanel/" + fi +} + # Function to install dependencies install_dependencies() { # Check if we're running from a file (not via curl) and modules are available @@ -238,6 +380,27 @@ install_cyberpanel() { install_cyberpanel_direct() { echo " 🔄 Downloading CyberPanel installation files..." + # Pre-installation system checks + echo " 🔍 Running pre-installation checks..." + + # Ensure system is up to date + if command -v dnf >/dev/null 2>&1; then + echo " Updating system packages..." + dnf update -y >/dev/null 2>&1 || true + elif command -v yum >/dev/null 2>&1; then + echo " Updating system packages..." + yum update -y >/dev/null 2>&1 || true + elif command -v apt >/dev/null 2>&1; then + echo " Updating system packages..." + apt update -y >/dev/null 2>&1 || true + apt upgrade -y >/dev/null 2>&1 || true + fi + + # Ensure required services are available + echo " Checking system services..." + systemctl enable mariadb 2>/dev/null || true + systemctl enable lsws 2>/dev/null || true + # Create temporary directory for installation local temp_dir="/tmp/cyberpanel_install_$$" mkdir -p "$temp_dir" @@ -418,10 +581,16 @@ install_cyberpanel_direct() { cd /tmp rm -rf "$temp_dir" 2>/dev/null || true - if [ $install_status -eq 0 ]; then - print_status "SUCCESS: CyberPanel installed successfully" - return 0 - else + if [ $install_status -eq 0 ]; then + print_status "SUCCESS: CyberPanel installed successfully" + + # Run post-installation fixes + echo "" + echo " 🔧 Running post-installation fixes..." + fix_post_install_issues + + return 0 + else print_status "ERROR: CyberPanel installation failed (exit code: $install_status)" echo "" echo "==============================================================================================================="