Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Use nginx location snippets and add doctor

Juan Denis39ac49609e74
diff --git a/backend/app/services/nginx_service.py b/backend/app/services/nginx_service.py
index 3fe20bd4..f322a44d 100644
--- a/backend/app/services/nginx_service.py
+++ b/backend/app/services/nginx_service.py
@@ -28,6 +28,7 @@ class NginxService:
SITES_AVAILABLE = os.path.join(NGINX_CONF_DIR, 'sites-available')
SITES_ENABLED = os.path.join(NGINX_CONF_DIR, 'sites-enabled')
NGINX_BIN = os.environ.get('NGINX_BIN', '/usr/sbin/nginx')
+ LOCATIONS_DIR = os.path.join(NGINX_CONF_DIR, 'serverkit-locations')
# Templates
PHP_SITE_TEMPLATE = '''server {{
@@ -182,74 +183,56 @@ class NginxService:
GITEA_CONFIG_NAME = 'serverkit-gitea'
WORDPRESS_CONFIG_NAME = 'serverkit-wordpress'
- # Gitea location block for /gitea path
- GITEA_LOCATION_TEMPLATE = '''server {{
- listen 80;
- listen [::]:80;
- server_name _;
-
- access_log /var/log/nginx/gitea.access.log;
- error_log /var/log/nginx/gitea.error.log;
-
- # Gitea at /gitea path
- location /gitea/ {{
- proxy_pass http://127.0.0.1:{port}/;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_set_header X-Forwarded-Host $host;
- proxy_cache_bypass $http_upgrade;
- proxy_read_timeout 86400;
- proxy_connect_timeout 60;
- proxy_send_timeout 60;
-
- # Required for Gitea WebSocket connections
- proxy_buffering off;
- client_max_body_size 100M;
- }}
+ # Gitea location block for /gitea path (included inside main server block)
+ GITEA_LOCATION_TEMPLATE = '''# Gitea at /gitea path
+location /gitea/ {{
+ proxy_pass http://127.0.0.1:{port}/;
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "upgrade";
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_cache_bypass $http_upgrade;
+ proxy_read_timeout 86400;
+ proxy_connect_timeout 60;
+ proxy_send_timeout 60;
+
+ # Required for Gitea WebSocket connections
+ proxy_buffering off;
+ client_max_body_size 100M;
+}}
- # Handle /gitea without trailing slash
- location = /gitea {{
- return 301 /gitea/;
- }}
+# Handle /gitea without trailing slash
+location = /gitea {{
+ return 301 /gitea/;
}}
'''
- # WordPress location block for /wordpress path
- WORDPRESS_LOCATION_TEMPLATE = '''server {{
- listen 80;
- listen [::]:80;
- server_name _;
-
- access_log /var/log/nginx/wordpress.access.log;
- error_log /var/log/nginx/wordpress.error.log;
-
- # WordPress at /wordpress path
- location /wordpress/ {{
- proxy_pass http://127.0.0.1:{port}/;
- proxy_http_version 1.1;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_set_header X-Forwarded-Host $host;
- proxy_cache_bypass $http_upgrade;
- proxy_read_timeout 300;
- proxy_connect_timeout 60;
- proxy_send_timeout 60;
-
- # WordPress file uploads
- client_max_body_size 256M;
- }}
+ # WordPress location block for /wordpress path (included inside main server block)
+ WORDPRESS_LOCATION_TEMPLATE = '''# WordPress at /wordpress path
+location /wordpress/ {{
+ proxy_pass http://127.0.0.1:{port}/;
+ proxy_http_version 1.1;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_cache_bypass $http_upgrade;
+ proxy_read_timeout 300;
+ proxy_connect_timeout 60;
+ proxy_send_timeout 60;
+
+ # WordPress file uploads
+ client_max_body_size 256M;
+}}
- # Handle /wordpress without trailing slash
- location = /wordpress {{
- return 301 /wordpress/;
- }}
+# Handle /wordpress without trailing slash
+location = /wordpress {{
+ return 301 /wordpress/;
}}
'''
@@ -430,6 +413,8 @@ server {{
# Validate all domains
for domain in domains:
+ if domain == '_':
+ return {'success': False, 'error': 'Wildcard server_name "_" is reserved for the ServerKit panel'}
if not _validate_domain(domain):
return {'success': False, 'error': f'Invalid domain name: {domain}'}
@@ -863,9 +848,17 @@ server {{
# ==================== GITEA CONFIGURATION ====================
+ @classmethod
+ def _ensure_locations_dir(cls):
+ """Ensure the serverkit-locations directory exists."""
+ run_privileged(['mkdir', '-p', cls.LOCATIONS_DIR])
+
@classmethod
def create_gitea_config(cls, port: int) -> Dict:
- """Create Nginx configuration for Gitea at /gitea path.
+ """Create Nginx location config for Gitea at /gitea path.
+
+ The config is a location-only snippet included inside the main
+ serverkit.conf server block, preventing server_name conflicts.
Args:
port: The internal port Gitea is running on
@@ -874,19 +867,17 @@ server {{
Dict with success status and message
"""
try:
+ cls._ensure_locations_dir()
config = cls.GITEA_LOCATION_TEMPLATE.format(port=port)
- config_path = os.path.join(cls.SITES_AVAILABLE, cls.GITEA_CONFIG_NAME)
+ config_path = os.path.join(cls.LOCATIONS_DIR, f'{cls.GITEA_CONFIG_NAME}.conf')
- # Write config file
+ # Write location snippet (no separate server block, no sites-enabled symlink)
process = run_privileged(['tee', config_path], input=config)
if process.returncode != 0:
return {'success': False, 'error': f'Failed to write config: {process.stderr}'}
- # Enable the site
- enabled_path = os.path.join(cls.SITES_ENABLED, cls.GITEA_CONFIG_NAME)
- result = run_privileged(['ln', '-sf', config_path, enabled_path])
- if result.returncode != 0:
- return {'success': False, 'error': f'Failed to enable config: {result.stderr}'}
+ # Clean up legacy separate server block if it exists
+ cls._remove_legacy_site(cls.GITEA_CONFIG_NAME)
# Reload Nginx
reload_result = cls.reload()
@@ -911,14 +902,13 @@ server {{
Dict with success status and message
"""
try:
- # Remove symlink
- enabled_path = os.path.join(cls.SITES_ENABLED, cls.GITEA_CONFIG_NAME)
- run_privileged(['rm', '-f', enabled_path])
-
- # Remove config file
- config_path = os.path.join(cls.SITES_AVAILABLE, cls.GITEA_CONFIG_NAME)
+ # Remove location snippet
+ config_path = os.path.join(cls.LOCATIONS_DIR, f'{cls.GITEA_CONFIG_NAME}.conf')
run_privileged(['rm', '-f', config_path])
+ # Clean up legacy separate server block if it exists
+ cls._remove_legacy_site(cls.GITEA_CONFIG_NAME)
+
# Reload Nginx
cls.reload()
@@ -940,7 +930,10 @@ server {{
@classmethod
def create_wordpress_config(cls, port: int) -> Dict:
- """Create Nginx configuration for WordPress at /wordpress path.
+ """Create Nginx location config for WordPress at /wordpress path.
+
+ The config is a location-only snippet included inside the main
+ serverkit.conf server block, preventing server_name conflicts.
Args:
port: The internal port WordPress is running on
@@ -949,19 +942,17 @@ server {{
Dict with success status and message
"""
try:
+ cls._ensure_locations_dir()
config = cls.WORDPRESS_LOCATION_TEMPLATE.format(port=port)
- config_path = os.path.join(cls.SITES_AVAILABLE, cls.WORDPRESS_CONFIG_NAME)
+ config_path = os.path.join(cls.LOCATIONS_DIR, f'{cls.WORDPRESS_CONFIG_NAME}.conf')
- # Write config file
+ # Write location snippet (no separate server block, no sites-enabled symlink)
process = run_privileged(['tee', config_path], input=config)
if process.returncode != 0:
return {'success': False, 'error': f'Failed to write config: {process.stderr}'}
- # Enable the site
- enabled_path = os.path.join(cls.SITES_ENABLED, cls.WORDPRESS_CONFIG_NAME)
- result = run_privileged(['ln', '-sf', config_path, enabled_path])
- if result.returncode != 0:
- return {'success': False, 'error': f'Failed to enable config: {result.stderr}'}
+ # Clean up legacy separate server block if it exists
+ cls._remove_legacy_site(cls.WORDPRESS_CONFIG_NAME)
# Reload Nginx
reload_result = cls.reload()
@@ -986,14 +977,13 @@ server {{
Dict with success status and message
"""
try:
- # Remove symlink
- enabled_path = os.path.join(cls.SITES_ENABLED, cls.WORDPRESS_CONFIG_NAME)
- run_privileged(['rm', '-f', enabled_path])
-
- # Remove config file
- config_path = os.path.join(cls.SITES_AVAILABLE, cls.WORDPRESS_CONFIG_NAME)
+ # Remove location snippet
+ config_path = os.path.join(cls.LOCATIONS_DIR, f'{cls.WORDPRESS_CONFIG_NAME}.conf')
run_privileged(['rm', '-f', config_path])
+ # Clean up legacy separate server block if it exists
+ cls._remove_legacy_site(cls.WORDPRESS_CONFIG_NAME)
+
# Reload Nginx
cls.reload()
@@ -1002,6 +992,16 @@ server {{
except Exception as e:
return {'success': False, 'error': str(e)}
+ @classmethod
+ def _remove_legacy_site(cls, name: str):
+ """Remove legacy separate server block configs from sites-available/enabled.
+
+ Old versions wrote WordPress/Gitea as full server blocks in sites-available
+ with symlinks in sites-enabled. This caused server_name conflicts.
+ """
+ run_privileged(['rm', '-f', os.path.join(cls.SITES_ENABLED, name)])
+ run_privileged(['rm', '-f', os.path.join(cls.SITES_AVAILABLE, name)])
+
@classmethod
def get_wordpress_config(cls) -> Dict:
"""Get the current WordPress nginx configuration.
diff --git a/install.sh b/install.sh
index fccad437..a26f9c57 100644
--- a/install.sh
+++ b/install.sh
@@ -395,12 +395,26 @@ rm -f /etc/nginx/sites-enabled/default
# Ensure sites directories exist
mkdir -p /etc/nginx/sites-available
mkdir -p /etc/nginx/sites-enabled
+mkdir -p /etc/nginx/serverkit-locations
# Ensure nginx.conf includes sites-enabled (Fedora uses conf.d by default)
if ! grep -q "sites-enabled" /etc/nginx/nginx.conf; then
sed -i '/http {/a \ include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf
fi
+# Remove any nginx configs that use server_name _ (catch-all) besides serverkit.conf
+# These conflict with the panel and can allow compromised apps to hijack all traffic
+for conf in /etc/nginx/sites-enabled/*; do
+ [ -f "$conf" ] || continue
+ name=$(basename "$conf")
+ [ "$name" = "serverkit.conf" ] && continue
+ if grep -q 'server_name.*_' "$conf" 2>/dev/null; then
+ print_warning "Removing conflicting catch-all config: $name"
+ rm -f "/etc/nginx/sites-enabled/$name"
+ rm -f "/etc/nginx/sites-available/$name"
+ fi
+done
+
# Install ServerKit site config
cp "$INSTALL_DIR/nginx/sites-available/serverkit.conf" /etc/nginx/sites-available/
ln -sf /etc/nginx/sites-available/serverkit.conf /etc/nginx/sites-enabled/
diff --git a/nginx/sites-available/serverkit.conf b/nginx/sites-available/serverkit.conf
index 82ab3bd8..f645daf0 100644
--- a/nginx/sites-available/serverkit.conf
+++ b/nginx/sites-available/serverkit.conf
@@ -13,7 +13,7 @@ server {
# return 301 https://$server_name$request_uri;
location / {
- proxy_pass http://127.0.0.1:8080;
+ proxy_pass http://127.0.0.1:3847;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -46,4 +46,8 @@ server {
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
+
+ # Include app location blocks (WordPress, Gitea, private URLs, etc.)
+ # These are location-only snippets, NOT separate server blocks.
+ include /etc/nginx/serverkit-locations/*.conf;
}
diff --git a/serverkit b/serverkit
index 1d606d68..06e1baeb 100644
--- a/serverkit
+++ b/serverkit
@@ -194,6 +194,10 @@ cmd_help() {
echo " version Show current version"
echo " check-update Check if updates are available"
echo ""
+ echo "Diagnostics:"
+ echo " doctor Check for common issues"
+ echo " doctor --fix Auto-fix detected issues"
+ echo ""
echo "Utility Commands:"
echo " generate-keys Generate secure keys for .env"
echo " config Edit configuration"
@@ -453,6 +457,24 @@ cmd_update() {
cp -r "$INSTALL_DIR/backend/templates/"*.yaml /etc/serverkit/templates/ 2>/dev/null || true
cp -r "$INSTALL_DIR/backend/templates/"*.yml /etc/serverkit/templates/ 2>/dev/null || true
+ # Remove any nginx configs that use server_name _ besides serverkit.conf
+ mkdir -p /etc/nginx/serverkit-locations
+ for conf in /etc/nginx/sites-enabled/*; do
+ [ -f "$conf" ] || continue
+ name=$(basename "$conf")
+ [ "$name" = "serverkit.conf" ] && continue
+ if grep -q 'server_name.*_' "$conf" 2>/dev/null; then
+ print_warning "Removing conflicting catch-all config: $name"
+ rm -f "/etc/nginx/sites-enabled/$name"
+ rm -f "/etc/nginx/sites-available/$name"
+ fi
+ done
+
+ # Update main nginx config
+ if [ -f "$INSTALL_DIR/nginx/sites-available/serverkit.conf" ]; then
+ cp "$INSTALL_DIR/nginx/sites-available/serverkit.conf" /etc/nginx/sites-available/
+ fi
+
# Clean up Docker to prevent networking issues
print_info "Cleaning up Docker..."
docker network prune -f 2>/dev/null || true
@@ -906,6 +928,296 @@ cmd_list_sites() {
echo ""
}
+cmd_doctor() {
+ check_installed
+ print_header
+ echo ""
+ print_info "Running diagnostics..."
+ echo ""
+
+ ISSUES=0
+ FIXED=0
+ FIX_MODE="${1:-}" # --fix to auto-fix
+
+ doctor_issue() {
+ ISSUES=$((ISSUES + 1))
+ print_error "$1"
+ }
+
+ doctor_ok() {
+ print_success "$1"
+ }
+
+ doctor_fixed() {
+ FIXED=$((FIXED + 1))
+ print_success "FIXED: $1"
+ }
+
+ doctor_skip() {
+ print_warning "SKIP: $1 (run with --fix to auto-fix)"
+ }
+
+ # ── 1. Backend service ──────────────────────────────────────
+ echo "Backend"
+ echo "───────────────────────────────────────"
+
+ if systemctl is-active --quiet $BACKEND_SERVICE 2>/dev/null; then
+ doctor_ok "systemd service is running"
+ else
+ doctor_issue "systemd service is not running"
+ if [ "$FIX_MODE" = "--fix" ]; then
+ systemctl start $BACKEND_SERVICE 2>/dev/null && doctor_fixed "Started backend service" || print_error " Could not start service"
+ else
+ doctor_skip "systemctl start $BACKEND_SERVICE"
+ fi
+ fi
+
+ if curl -sf http://127.0.0.1:5000/api/v1/system/health > /dev/null 2>&1; then
+ doctor_ok "API responding on port 5000"
+ else
+ if systemctl is-active --quiet $BACKEND_SERVICE 2>/dev/null; then
+ doctor_issue "Service running but API not responding on port 5000"
+ echo " Check logs: journalctl -u serverkit -n 30"
+ else
+ doctor_issue "API not responding (service is down)"
+ fi
+ fi
+
+ echo ""
+
+ # ── 2. Frontend container ───────────────────────────────────
+ echo "Frontend"
+ echo "───────────────────────────────────────"
+
+ FRONTEND_RUNNING=false
+ FRONTEND_PORT=""
+
+ if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "$FRONTEND_CONTAINER"; then
+ FRONTEND_RUNNING=true
+ # Get the actual host port the container is mapped to
+ FRONTEND_PORT=$(docker port "$FRONTEND_CONTAINER" 80 2>/dev/null | head -1 | grep -oP ':\K[0-9]+' || echo "")
+ doctor_ok "Container running (port $FRONTEND_PORT)"
+ else
+ doctor_issue "Container '$FRONTEND_CONTAINER' is not running"
+ if [ "$FIX_MODE" = "--fix" ]; then
+ cd "$INSTALL_DIR"
+ docker compose up -d 2>/dev/null && {
+ sleep 3
+ FRONTEND_PORT=$(docker port "$FRONTEND_CONTAINER" 80 2>/dev/null | head -1 | grep -oP ':\K[0-9]+' || echo "")
+ FRONTEND_RUNNING=true
+ doctor_fixed "Started frontend container (port $FRONTEND_PORT)"
+ } || print_error " Could not start container"
+ else
+ doctor_skip "docker compose up -d"
+ fi
+ fi
+
+ if [ "$FRONTEND_RUNNING" = true ] && [ -n "$FRONTEND_PORT" ]; then
+ if curl -sf "http://127.0.0.1:$FRONTEND_PORT" > /dev/null 2>&1; then
+ doctor_ok "Frontend responding on port $FRONTEND_PORT"
+ else
+ doctor_issue "Container running but not responding on port $FRONTEND_PORT"
+ fi
+ fi
+
+ echo ""
+
+ # ── 3. Nginx ────────────────────────────────────────────────
+ echo "Nginx"
+ echo "───────────────────────────────────────"
+
+ if systemctl is-active --quiet nginx 2>/dev/null; then
+ doctor_ok "nginx is running"
+ else
+ doctor_issue "nginx is not running"
+ if [ "$FIX_MODE" = "--fix" ]; then
+ systemctl start nginx 2>/dev/null && doctor_fixed "Started nginx" || print_error " Could not start nginx"
+ else
+ doctor_skip "systemctl start nginx"
+ fi
+ fi
+
+ if nginx -t 2>/dev/null; then
+ doctor_ok "nginx config syntax OK"
+ else
+ doctor_issue "nginx config has errors"
+ echo " Run: nginx -t"
+ fi
+
+ # Scan ALL enabled nginx configs for competing server_name _
+ # Only serverkit.conf should use server_name _ (the catch-all panel block)
+ for SITE_CONF in /etc/nginx/sites-enabled/*; do
+ [ -f "$SITE_CONF" ] || continue
+ SITE_NAME=$(basename "$SITE_CONF")
+ [ "$SITE_NAME" = "serverkit.conf" ] && continue
+
+ if grep -q 'server_name\s*_' "$SITE_CONF" 2>/dev/null; then
+ doctor_issue "'$SITE_NAME' uses server_name _ (conflicts with panel, can hijack all traffic)"
+ if [ "$FIX_MODE" = "--fix" ]; then
+ rm -f "/etc/nginx/sites-enabled/$SITE_NAME"
+ rm -f "/etc/nginx/sites-available/$SITE_NAME"
+ doctor_fixed "Removed conflicting '$SITE_NAME'"
+ else
+ doctor_skip "Remove conflicting '$SITE_NAME' from sites-enabled"
+ fi
+ fi
+ done
+
+ # Ensure serverkit-locations directory exists
+ if [ ! -d /etc/nginx/serverkit-locations ]; then
+ print_warning "Missing /etc/nginx/serverkit-locations directory"
+ if [ "$FIX_MODE" = "--fix" ]; then
+ mkdir -p /etc/nginx/serverkit-locations
+ doctor_fixed "Created /etc/nginx/serverkit-locations"
+ else
+ doctor_skip "mkdir -p /etc/nginx/serverkit-locations"
+ fi
+ fi
+
+ # Check for port mismatch between nginx and frontend container
+ NGINX_CONF="/etc/nginx/sites-available/serverkit.conf"
+ if [ -f "$NGINX_CONF" ]; then
+ NGINX_FRONTEND_PORT=$(grep -m1 'proxy_pass.*127.0.0.1' "$NGINX_CONF" | head -1 | grep -oP ':\K[0-9]+' || echo "")
+
+ if [ -n "$FRONTEND_PORT" ] && [ -n "$NGINX_FRONTEND_PORT" ]; then
+ if [ "$NGINX_FRONTEND_PORT" = "$FRONTEND_PORT" ]; then
+ doctor_ok "nginx proxy port ($NGINX_FRONTEND_PORT) matches frontend container ($FRONTEND_PORT)"
+ else
+ doctor_issue "PORT MISMATCH: nginx proxies to :$NGINX_FRONTEND_PORT but frontend is on :$FRONTEND_PORT"
+ if [ "$FIX_MODE" = "--fix" ]; then
+ sed -i "s|proxy_pass http://127.0.0.1:${NGINX_FRONTEND_PORT}|proxy_pass http://127.0.0.1:${FRONTEND_PORT}|" "$NGINX_CONF"
+ if nginx -t 2>/dev/null; then
+ nginx -s reload 2>/dev/null
+ doctor_fixed "Updated nginx to proxy to port $FRONTEND_PORT"
+ else
+ print_error " nginx config broken after edit — reverting"
+ sed -i "s|proxy_pass http://127.0.0.1:${FRONTEND_PORT}|proxy_pass http://127.0.0.1:${NGINX_FRONTEND_PORT}|" "$NGINX_CONF"
+ fi
+ else
+ doctor_skip "Update nginx proxy_pass from :$NGINX_FRONTEND_PORT to :$FRONTEND_PORT"
+ fi
+ fi
+ fi
+
+ # Check API proxy port
+ NGINX_API_PORT=$(grep -A1 'location /api' "$NGINX_CONF" | grep proxy_pass | grep -oP ':\K[0-9]+' || echo "")
+ if [ -n "$NGINX_API_PORT" ]; then
+ if ss -tlnp 2>/dev/null | grep -q ":${NGINX_API_PORT}.*gunicorn\|:${NGINX_API_PORT}.*python"; then
+ doctor_ok "nginx API proxy port ($NGINX_API_PORT) has backend listening"
+ else
+ doctor_issue "nginx proxies API to :$NGINX_API_PORT but nothing is listening there"
+ fi
+ fi
+ else
+ doctor_issue "nginx config not found: $NGINX_CONF"
+ fi
+
+ echo ""
+
+ # ── 4. Docker ───────────────────────────────────────────────
+ echo "Docker"
+ echo "───────────────────────────────────────"
+
+ if command -v docker &>/dev/null; then
+ doctor_ok "Docker installed"
+ else
+ doctor_issue "Docker not found"
+ fi
+
+ if docker info &>/dev/null; then
+ doctor_ok "Docker daemon running"
+ else
+ doctor_issue "Docker daemon not running"
+ if [ "$FIX_MODE" = "--fix" ]; then
+ systemctl start docker 2>/dev/null && doctor_fixed "Started Docker daemon" || print_error " Could not start Docker"
+ else
+ doctor_skip "systemctl start docker"
+ fi
+ fi
+
+ echo ""
+
+ # ── 5. Disk space ───────────────────────────────────────────
+ echo "System"
+ echo "───────────────────────────────────────"
+
+ DISK_USAGE=$(df / | awk 'NR==2 {print $5}' | tr -d '%')
+ if [ "$DISK_USAGE" -lt 90 ]; then
+ doctor_ok "Disk usage: ${DISK_USAGE}%"
+ elif [ "$DISK_USAGE" -lt 95 ]; then
+ print_warning "Disk usage high: ${DISK_USAGE}%"
+ else
+ doctor_issue "Disk almost full: ${DISK_USAGE}%"
+ fi
+
+ RAM_AVAIL=$(free -m | awk '/Mem:/ {print $7}')
+ if [ "$RAM_AVAIL" -gt 100 ]; then
+ doctor_ok "Available RAM: ${RAM_AVAIL}MB"
+ else
+ doctor_issue "Low RAM: ${RAM_AVAIL}MB available"
+ fi
+
+ # Check swap
+ SWAP_TOTAL=$(free -m | awk '/^Swap:/ {print $2}')
+ if [ "$SWAP_TOTAL" -gt 0 ]; then
+ doctor_ok "Swap: ${SWAP_TOTAL}MB"
+ else
+ print_warning "No swap configured (recommended for low-RAM servers)"
+ fi
+
+ echo ""
+
+ # ── 6. Database ─────────────────────────────────────────────
+ echo "Database"
+ echo "───────────────────────────────────────"
+
+ DB_FILE="$INSTALL_DIR/backend/instance/serverkit.db"
+ if [ -f "$DB_FILE" ]; then
+ DB_SIZE=$(du -h "$DB_FILE" | cut -f1)
+ doctor_ok "SQLite database exists ($DB_SIZE)"
+ else
+ doctor_issue "Database file not found: $DB_FILE"
+ fi
+
+ echo ""
+
+ # ── 7. Connectivity ─────────────────────────────────────────
+ echo "Connectivity"
+ echo "───────────────────────────────────────"
+
+ if curl -sf http://127.0.0.1 > /dev/null 2>&1; then
+ doctor_ok "localhost:80 responding"
+ else
+ doctor_issue "localhost:80 not responding (nginx → frontend broken)"
+ fi
+
+ if curl -sf http://127.0.0.1/api/v1/system/health > /dev/null 2>&1; then
+ doctor_ok "localhost:80/api proxying to backend"
+ else
+ doctor_issue "localhost:80/api not reaching backend"
+ fi
+
+ echo ""
+
+ # ── Summary ─────────────────────────────────────────────────
+ echo "───────────────────────────────────────"
+ if [ "$ISSUES" -eq 0 ]; then
+ print_success "All checks passed!"
+ else
+ if [ "$FIX_MODE" = "--fix" ]; then
+ echo -e "${YELLOW}Found $ISSUES issue(s), fixed $FIXED${NC}"
+ REMAINING=$((ISSUES - FIXED))
+ if [ "$REMAINING" -gt 0 ]; then
+ echo "$REMAINING issue(s) need manual attention"
+ fi
+ else
+ echo -e "${RED}Found $ISSUES issue(s)${NC}"
+ echo "Run 'sudo serverkit doctor --fix' to auto-fix"
+ fi
+ fi
+ echo ""
+}
+
cmd_remove_site() {
check_root
@@ -1046,6 +1358,9 @@ case "${1:-help}" in
remove-site)
cmd_remove_site "$2"
;;
+ doctor)
+ cmd_doctor "$2"
+ ;;
*)
print_error "Unknown command: $1"
echo "Run 'serverkit help' for usage"