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.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
Refactor to run backend on host, frontend in Docker
Juan Denisc95d01b2fbaf
diff --git a/docker-compose.prod.yml b/docker-compose.prod.ymldeleted file mode 100644index 2c6b6fac..00000000--- a/docker-compose.prod.yml+++ /dev/null@@ -1,74 +0,0 @@-# Docker Compose - Production Configuration-version: '3.8'--services:- backend:- build:- context: ./backend- dockerfile: Dockerfile- container_name: serverkit-backend- environment:- - FLASK_ENV=production- - DATABASE_URL=${DATABASE_URL:-sqlite:///serverkit.db}- - SECRET_KEY=${SECRET_KEY}- - JWT_SECRET_KEY=${JWT_SECRET_KEY}- - CORS_ORIGINS=${CORS_ORIGINS:-https://yourdomain.com}- volumes:- - backend-data:/app/instance- - /var/log:/var/log:ro- - /home:/home:ro- - /opt:/opt:ro- networks:- - serverkit-network- restart: always- logging:- driver: "json-file"- options:- max-size: "10m"- max-file: "3"-- frontend:- build:- context: ./frontend- dockerfile: Dockerfile- container_name: serverkit-frontend- depends_on:- - backend- networks:- - serverkit-network- restart: always- logging:- driver: "json-file"- options:- max-size: "10m"- max-file: "3"-- nginx:- image: nginx:alpine- container_name: serverkit-nginx- depends_on:- - frontend- - backend- ports:- - "80:80"- - "443:443"- volumes:- - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro- - ./nginx/ssl:/etc/nginx/ssl:ro- - nginx-cache:/var/cache/nginx- networks:- - serverkit-network- restart: always- logging:- driver: "json-file"- options:- max-size: "10m"- max-file: "3"--networks:- serverkit-network:- driver: bridge--volumes:- backend-data:- nginx-cache:diff --git a/docker-compose.yml b/docker-compose.ymlindex 31f58ad2..9a19522a 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -1,75 +1,27 @@# ============================================# ServerKit Docker Compose# ============================================+# The backend runs directly on the host (not in Docker)+# for full system access. Only the frontend runs in Docker.+## Usage:# 1. Copy .env.example to .env and configure-# 2. Run: docker compose up -d-#-# For production with SSL:-# docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d+# 2. Start backend: sudo systemctl start serverkit+# 3. Start frontend: docker compose up -d# ============================================services:- backend:- build:- context: ./backend- dockerfile: Dockerfile- container_name: serverkit-backend- environment:- # Flask Configuration- - FLASK_ENV=${FLASK_ENV:-production}- - PORT=5000-- # Security Keys (REQUIRED - generate with: python -c "import secrets; print(secrets.token_hex(32))")- - SECRET_KEY=${SECRET_KEY:?SECRET_KEY is required}- - JWT_SECRET_KEY=${JWT_SECRET_KEY:?JWT_SECRET_KEY is required}-- # Database (4 slashes = absolute path for SQLite)- - DATABASE_URL=${DATABASE_URL:-sqlite:////app/instance/serverkit.db}-- # CORS Origins (comma-separated list)- - CORS_ORIGINS=${CORS_ORIGINS:-http://localhost,http://localhost:80}- volumes:- # Application data (database)- - serverkit-data:/app/instance-- # ServerKit configuration (notifications, security settings, etc.)- - serverkit-config:/etc/serverkit-- # ServerKit logs (using /app/logs to avoid conflict with host /var/log mount)- - serverkit-logs:/app/logs-- # Quarantine directory for malware- - serverkit-quarantine:/var/quarantine-- # Docker socket (for container management)- - /var/run/docker.sock:/var/run/docker.sock:ro- networks:- - serverkit-network- restart: unless-stopped- healthcheck:- test: ["CMD", "curl", "-f", "http://localhost:5000/api/v1/system/health"]- interval: 30s- timeout: 10s- retries: 3- start_period: 15s- logging:- driver: "json-file"- options:- max-size: "10m"- max-file: "3"-frontend:build:context: ./frontenddockerfile: Dockerfilecontainer_name: serverkit-frontend- depends_on:- backend:- condition: service_healthyports:- "${PORT:-80}:80"- "${SSL_PORT:-443}:443"+ extra_hosts:+ # Allows container to reach the host machine where backend runs+ - "host.docker.internal:host-gateway"volumes:- ./nginx/ssl:/etc/nginx/ssl:ronetworks:@@ -90,13 +42,3 @@ networks:serverkit-network:driver: bridgename: serverkit-network--volumes:- serverkit-data:- name: serverkit-data- serverkit-config:- name: serverkit-config- serverkit-logs:- name: serverkit-logs- serverkit-quarantine:- name: serverkit-quarantinediff --git a/frontend/nginx.conf b/frontend/nginx.confindex 4fe07017..253ef1d7 100644--- a/frontend/nginx.conf+++ b/frontend/nginx.conf@@ -23,9 +23,9 @@ server {try_files $uri $uri/ /index.html;}- # Proxy API requests to backend+ # Proxy API requests to backend (running on host, not in Docker)location /api {- proxy_pass http://backend:5000;+ proxy_pass http://host.docker.internal:5000;proxy_http_version 1.1;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;@@ -38,9 +38,9 @@ server {proxy_read_timeout 60s;}- # WebSocket support for socket.io+ # WebSocket support for socket.io (running on host, not in Docker)location /socket.io {- proxy_pass http://backend:5000;+ proxy_pass http://host.docker.internal:5000;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";diff --git a/install.sh b/install.shindex 27dfd102..4a88d917 100644--- a/install.sh+++ b/install.sh@@ -1,6 +1,11 @@#!/bin/bash#-# ServerKit Quick Install Script for Ubuntu+# ServerKit Quick Install Script for Ubuntu/Debian+#+# Architecture:+# - Backend: Runs directly on host (for full system access)+# - Frontend: Runs in Docker (nginx serving static files)+## Usage: curl -fsSL https://raw.githubusercontent.com/jhd3197/serverkit/main/install.sh | bash#@@ -13,117 +18,214 @@ YELLOW='\033[1;33m'BLUE='\033[0;34m'NC='\033[0m'-echo -e "${BLUE}"-echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"-echo " ServerKit Installer"-echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"-echo -e "${NC}"+INSTALL_DIR="/opt/serverkit"+VENV_DIR="$INSTALL_DIR/venv"+LOG_DIR="/var/log/serverkit"+DATA_DIR="/var/lib/serverkit"++print_header() {+ echo -e "${BLUE}"+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"+ echo " ServerKit Installer"+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"+ echo -e "${NC}"+}++print_success() { echo -e "${GREEN}✓ $1${NC}"; }+print_error() { echo -e "${RED}✗ $1${NC}"; }+print_warning() { echo -e "${YELLOW}! $1${NC}"; }+print_info() { echo -e "${BLUE}→ $1${NC}"; }++print_header# Check if running as root-if [ "$EUID" -eq 0 ]; then- echo -e "${YELLOW}Warning: Running as root is not recommended${NC}"+if [ "$EUID" -ne 0 ]; then+ print_error "Please run as root (sudo)"+ exit 1fi-# Check Ubuntu+# Check Ubuntu/Debianif [ -f /etc/os-release ]; then. /etc/os-releaseif [ "$ID" != "ubuntu" ] && [ "$ID" != "debian" ]; then- echo -e "${YELLOW}Warning: This script is designed for Ubuntu/Debian${NC}"+ print_warning "This script is designed for Ubuntu/Debian. Proceed with caution."fifi-echo -e "${BLUE}→ Checking prerequisites...${NC}"+echo ""+print_info "Installing system dependencies..."++# Update package list+apt-get update++# Install Python and required packages+apt-get install -y \+ python3 \+ python3-pip \+ python3-venv \+ python3-dev \+ git \+ curl \+ build-essential \+ libffi-dev \+ libssl-dev \+ iproute2 \+ procps++print_success "System dependencies installed"# Install Docker if not presentif ! command -v docker &> /dev/null; then- echo -e "${BLUE}→ Installing Docker...${NC}"+ print_info "Installing Docker..."curl -fsSL https://get.docker.com | sh- sudo usermod -aG docker $USER- echo -e "${GREEN}✓ Docker installed${NC}"- echo -e "${YELLOW}! You may need to log out and back in for Docker permissions${NC}"+ systemctl enable docker+ systemctl start docker+ print_success "Docker installed"+else+ print_success "Docker already installed"fi# Install Docker Compose plugin if not presentif ! docker compose version &> /dev/null; then- echo -e "${BLUE}→ Installing Docker Compose...${NC}"- sudo apt-get update- sudo apt-get install -y docker-compose-plugin- echo -e "${GREEN}✓ Docker Compose installed${NC}"-fi--# Install git if not present-if ! command -v git &> /dev/null; then- echo -e "${BLUE}→ Installing git...${NC}"- sudo apt-get update- sudo apt-get install -y git+ print_info "Installing Docker Compose..."+ apt-get install -y docker-compose-plugin+ print_success "Docker Compose installed"+else+ print_success "Docker Compose already installed"fi-# Clone repository-INSTALL_DIR="/opt/serverkit"-echo -e "${BLUE}→ Installing ServerKit to $INSTALL_DIR...${NC}"+# Clone or update repository+print_info "Installing ServerKit to $INSTALL_DIR..."if [ -d "$INSTALL_DIR" ]; then- echo -e "${YELLOW}! Directory exists, updating...${NC}"+ print_warning "Directory exists, updating..."cd "$INSTALL_DIR"- sudo git pull+ git fetch origin+ git reset --hard origin/mainelse- sudo git clone https://github.com/jhd3197/serverkit.git "$INSTALL_DIR"+ git clone https://github.com/jhd3197/serverkit.git "$INSTALL_DIR"cd "$INSTALL_DIR"fi-# Set permissions-sudo chown -R $USER:$USER "$INSTALL_DIR"+print_success "Repository cloned"++# Create directories+print_info "Creating directories..."+mkdir -p "$LOG_DIR"+mkdir -p "$DATA_DIR"+mkdir -p "$INSTALL_DIR/backend/instance"+mkdir -p "$INSTALL_DIR/nginx/ssl"-# Make CLI executable-chmod +x serverkit+# Set up Python virtual environment+print_info "Setting up Python virtual environment..."+python3 -m venv "$VENV_DIR"+source "$VENV_DIR/bin/activate"-# Create symlink for global access-sudo ln -sf "$INSTALL_DIR/serverkit" /usr/local/bin/serverkit+# Install Python dependencies+print_info "Installing Python dependencies..."+pip install --upgrade pip+pip install -r "$INSTALL_DIR/backend/requirements.txt"+pip install gunicorn gevent gevent-websocket-# Generate configuration-if [ ! -f ".env" ]; then- echo -e "${BLUE}→ Generating configuration...${NC}"+print_success "Python dependencies installed"++# Generate .env if not exists+if [ ! -f "$INSTALL_DIR/.env" ]; then+ print_info "Generating configuration..."SECRET_KEY=$(openssl rand -hex 32)JWT_SECRET_KEY=$(openssl rand -hex 32)- cat > .env << EOF+ cat > "$INSTALL_DIR/.env" << EOF# ServerKit Configuration+# Generated on $(date)++# Security Keys (auto-generated, keep secret!)SECRET_KEY=$SECRET_KEYJWT_SECRET_KEY=$JWT_SECRET_KEY-DATABASE_URL=sqlite:///serverkit.db-CORS_ORIGINS=http://localhost++# Database (SQLite by default)+DATABASE_URL=sqlite:///$INSTALL_DIR/backend/instance/serverkit.db++# CORS Origins (comma-separated, add your domain)+CORS_ORIGINS=http://localhost,https://localhost++# PortsPORT=80SSL_PORT=443++# EnvironmentFLASK_ENV=productionEOF-fi-# Create SSL directory-mkdir -p nginx/ssl+ print_success "Configuration generated"+else+ print_warning ".env already exists, keeping existing configuration"+fi-# Generate self-signed certificate-if [ ! -f "nginx/ssl/fullchain.pem" ]; then- echo -e "${BLUE}→ Generating SSL certificate...${NC}"+# Generate self-signed SSL certificate if not exists+if [ ! -f "$INSTALL_DIR/nginx/ssl/fullchain.pem" ]; then+ print_info "Generating self-signed SSL certificate..."openssl req -x509 -nodes -days 365 -newkey rsa:2048 \- -keyout nginx/ssl/privkey.pem \- -out nginx/ssl/fullchain.pem \+ -keyout "$INSTALL_DIR/nginx/ssl/privkey.pem" \+ -out "$INSTALL_DIR/nginx/ssl/fullchain.pem" \-subj "/CN=localhost" 2>/dev/null+ print_warning "Self-signed certificate created. Replace with real cert for production."fi-# Build and start-echo -e "${BLUE}→ Building containers (this may take a few minutes)...${NC}"+# Install systemd service for backend+print_info "Installing systemd service..."+cp "$INSTALL_DIR/serverkit-backend.service" /etc/systemd/system/serverkit.service++# Reload systemd and enable service+systemctl daemon-reload+systemctl enable serverkit++print_success "Systemd service installed"++# Make CLI executable and create symlink+chmod +x "$INSTALL_DIR/serverkit"+ln -sf "$INSTALL_DIR/serverkit" /usr/local/bin/serverkit++print_success "CLI installed"++# Build and start frontend container+print_info "Building frontend container..."+cd "$INSTALL_DIR"docker compose build-echo -e "${BLUE}→ Starting services...${NC}"+print_info "Starting services..."++# Start backend (systemd)+systemctl start serverkit++# Start frontend (Docker)docker compose up -d-# Wait for services-echo -e "${BLUE}→ Waiting for services...${NC}"-sleep 15+# Wait for services to start+print_info "Waiting for services to start..."+sleep 10-# Final check+# Health checkecho ""+BACKEND_OK=false+FRONTEND_OK=false++if curl -s http://127.0.0.1:5000/api/v1/system/health > /dev/null 2>&1; then+ BACKEND_OK=true+ print_success "Backend is running"+else+ print_error "Backend health check failed"+fi+if curl -s http://localhost > /dev/null 2>&1; then+ FRONTEND_OK=true+ print_success "Frontend is running"+else+ print_error "Frontend health check failed"+fi++echo ""+if [ "$BACKEND_OK" = true ] && [ "$FRONTEND_OK" = true ]; thenecho -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"echo -e "${GREEN} Installation Complete!${NC}"echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"@@ -135,6 +237,10 @@ if curl -s http://localhost > /dev/null 2>&1; thenecho " 2. View status: serverkit status"echo " 3. View logs: serverkit logs"echo ""+ echo "Service Management:"+ echo " Backend (systemd): systemctl [start|stop|restart] serverkit"+ echo " Frontend (Docker): docker compose -C $INSTALL_DIR [up|down]"+ echo ""echo "For all commands: serverkit help"echo ""else@@ -142,6 +248,8 @@ elseecho -e "${RED} Installation may have issues${NC}"echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"echo ""- echo "Check logs with: serverkit logs"+ echo "Troubleshooting:"+ echo " Backend logs: journalctl -u serverkit -f"+ echo " Frontend logs: docker compose -C $INSTALL_DIR logs -f"echo ""fidiff --git a/nginx/nginx.conf b/nginx/nginx.confindex dd835bc5..c058b2fc 100644--- a/nginx/nginx.conf+++ b/nginx/nginx.conf@@ -43,13 +43,15 @@ http {limit_conn_zone $binary_remote_addr zone=conn_limit:10m;# Upstream servers+ # Backend runs on host, not in Dockerupstream backend {- server backend:5000;+ server 127.0.0.1:5000;keepalive 32;}+ # Frontend runs in Dockerupstream frontend {- server frontend:80;+ server host.docker.internal:8080;}# HTTP server - redirect to HTTPSdiff --git a/serverkit b/serverkitindex 66c7073a..ac02cc62 100644--- a/serverkit+++ b/serverkit@@ -1,7 +1,12 @@#!/bin/bash## ServerKit CLI - Management tool for ServerKit-# Usage: ./serverkit <command> [options]+#+# Architecture:+# - Backend: systemd service (runs directly on host)+# - Frontend: Docker container (nginx)+#+# Usage: serverkit <command> [options]#set -e@@ -11,12 +16,13 @@ RED='\033[0;31m'GREEN='\033[0;32m'YELLOW='\033[1;33m'BLUE='\033[0;34m'-NC='\033[0m' # No Color+NC='\033[0m'# ConfigurationINSTALL_DIR="${SERVERKIT_DIR:-/opt/serverkit}"-CONTAINER_NAME="serverkit-backend"-COMPOSE_FILE="docker-compose.yml"+VENV_DIR="$INSTALL_DIR/venv"+BACKEND_SERVICE="serverkit"+FRONTEND_CONTAINER="serverkit-frontend"# Helper functionsprint_header() {@@ -25,43 +31,31 @@ print_header() {echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"}-print_success() {- echo -e "${GREEN}✓ $1${NC}"-}--print_error() {- echo -e "${RED}✗ $1${NC}"-}--print_warning() {- echo -e "${YELLOW}! $1${NC}"-}+print_success() { echo -e "${GREEN}✓ $1${NC}"; }+print_error() { echo -e "${RED}✗ $1${NC}"; }+print_warning() { echo -e "${YELLOW}! $1${NC}"; }+print_info() { echo -e "${BLUE}→ $1${NC}"; }-print_info() {- echo -e "${BLUE}→ $1${NC}"-}--check_docker() {- if ! command -v docker &> /dev/null; then- print_error "Docker is not installed"- exit 1- fi- if ! docker info &> /dev/null; then- print_error "Docker is not running or you don't have permission"+check_root() {+ if [ "$EUID" -ne 0 ]; then+ print_error "This command requires root privileges. Run with sudo."exit 1fi}check_installed() {- if [ ! -f "$INSTALL_DIR/$COMPOSE_FILE" ]; then+ if [ ! -d "$INSTALL_DIR" ]; thenprint_error "ServerKit is not installed in $INSTALL_DIR"- print_info "Run: ./serverkit install"+ print_info "Run the install script first"exit 1fi}run_cli() {- docker exec -it $CONTAINER_NAME python cli.py "$@"+ # Run CLI commands directly on host using the virtual environment+ cd "$INSTALL_DIR/backend"+ source "$VENV_DIR/bin/activate"+ python cli.py "$@"}# Commands@@ -71,7 +65,6 @@ cmd_help() {echo "Usage: serverkit <command> [options]"echo ""echo "Service Commands:"- echo " install Install ServerKit"echo " start Start all services"echo " stop Stop all services"echo " restart Restart all services"@@ -96,186 +89,190 @@ cmd_help() {echo ""echo "Utility Commands:"echo " generate-keys Generate secure keys for .env"- echo " shell Open a shell in the backend container"echo " config Edit configuration"echo ""echo "Examples:"- echo " serverkit install"- echo " serverkit reset-password"+ echo " sudo serverkit start"+ echo " sudo serverkit create-admin"echo " serverkit logs backend"echo ""}-cmd_install() {- print_header- echo ""- print_info "Installing ServerKit..."-- check_docker-- # Check if already installed- if [ -d "$INSTALL_DIR" ] && [ -f "$INSTALL_DIR/$COMPOSE_FILE" ]; then- print_warning "ServerKit is already installed in $INSTALL_DIR"- read -p "Reinstall? (y/N) " -n 1 -r- echo- if [[ ! $REPLY =~ ^[Yy]$ ]]; then- exit 0- fi- fi-- # Create install directory- sudo mkdir -p "$INSTALL_DIR"+cmd_start() {+ check_root+ check_installed+ print_info "Starting ServerKit..."- # Clone or copy files- if [ -d ".git" ]; then- print_info "Copying files to $INSTALL_DIR..."- sudo cp -r . "$INSTALL_DIR/"- else- print_info "Cloning repository..."- sudo git clone https://github.com/jhd3197/serverkit.git "$INSTALL_DIR"- fi+ # Start backend (systemd)+ systemctl start $BACKEND_SERVICE+ # Start frontend (Docker)cd "$INSTALL_DIR"-- # Generate .env if not exists- if [ ! -f ".env" ]; then- print_info "Generating configuration..."- SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))" 2>/dev/null || openssl rand -hex 32)- JWT_SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))" 2>/dev/null || openssl rand -hex 32)-- cat > .env << EOF-# ServerKit Configuration-# Generated on $(date)--# Security Keys (auto-generated)-SECRET_KEY=$SECRET_KEY-JWT_SECRET_KEY=$JWT_SECRET_KEY--# Database-DATABASE_URL=sqlite:///serverkit.db--# CORS Origins (your domain)-CORS_ORIGINS=http://localhost--# Ports-PORT=80-SSL_PORT=443--# Environment-FLASK_ENV=production-EOF- print_success "Configuration file created"- fi-- # Create SSL directory- mkdir -p nginx/ssl-- # Generate self-signed cert for initial setup- if [ ! -f "nginx/ssl/fullchain.pem" ]; then- print_info "Generating self-signed SSL certificate..."- openssl req -x509 -nodes -days 365 -newkey rsa:2048 \- -keyout nginx/ssl/privkey.pem \- -out nginx/ssl/fullchain.pem \- -subj "/CN=localhost" 2>/dev/null- print_warning "Self-signed certificate created. Replace with real certificate for production."- fi-- # Build and start- print_info "Building containers..."- docker compose build-- print_info "Starting services..."docker compose up -d- # Wait for services- print_info "Waiting for services to be ready..."- sleep 10-- # Check status- if docker compose ps | grep -q "running"; then- echo ""- print_success "ServerKit installed successfully!"- echo ""- echo "Next steps:"- echo " 1. Open http://localhost in your browser"- echo " 2. Create your admin account: serverkit create-admin"- echo " 3. Configure SSL certificate for production"- echo ""- else- print_error "Installation failed. Check logs with: serverkit logs"- exit 1- fi-}--cmd_start() {- check_installed- cd "$INSTALL_DIR"- print_info "Starting ServerKit..."- docker compose up -d+ sleep 3print_success "ServerKit started"+ cmd_status_brief}cmd_stop() {+ check_rootcheck_installed- cd "$INSTALL_DIR"print_info "Stopping ServerKit..."- docker compose down++ # Stop backend (systemd)+ systemctl stop $BACKEND_SERVICE || true++ # Stop frontend (Docker)+ cd "$INSTALL_DIR"+ docker compose down || true+print_success "ServerKit stopped"}cmd_restart() {+ check_rootcheck_installed- cd "$INSTALL_DIR"print_info "Restarting ServerKit..."++ # Restart backend (systemd)+ systemctl restart $BACKEND_SERVICE++ # Restart frontend (Docker)+ cd "$INSTALL_DIR"docker compose restart++ sleep 3print_success "ServerKit restarted"+ cmd_status_brief+}++cmd_status_brief() {+ # Quick status check+ echo ""++ # Backend status+ if systemctl is-active --quiet $BACKEND_SERVICE; then+ print_success "Backend: running"+ else+ print_error "Backend: stopped"+ fi++ # Frontend status+ if docker ps --format '{{.Names}}' | grep -q $FRONTEND_CONTAINER; then+ print_success "Frontend: running"+ else+ print_error "Frontend: stopped"+ fi++ # API health+ if curl -s http://127.0.0.1:5000/api/v1/system/health > /dev/null 2>&1; then+ print_success "API: healthy"+ else+ print_warning "API: not responding"+ fi}cmd_status() {check_installed- cd "$INSTALL_DIR"print_headerecho ""- docker compose ps++ echo "Backend Service (systemd):"+ echo "─────────────────────────────"+ systemctl status $BACKEND_SERVICE --no-pager -l 2>/dev/null || print_warning "Backend service not found"+echo ""+ echo "Frontend Container (Docker):"+ echo "─────────────────────────────"+ cd "$INSTALL_DIR"+ docker compose ps 2>/dev/null || print_warning "Frontend container not found"- # Health check- if curl -s http://localhost/api/v1/health > /dev/null 2>&1; then- print_success "API is healthy"- else- print_warning "API health check failed"- fi+ echo ""+ cmd_status_brief}cmd_logs() {check_installed- cd "$INSTALL_DIR"- service="${1:-}"- if [ -n "$service" ]; then- docker compose logs -f "$service"- else- docker compose logs -f- fi+ service="${1:-all}"++ case "$service" in+ backend)+ journalctl -u $BACKEND_SERVICE -f+ ;;+ frontend)+ cd "$INSTALL_DIR"+ docker compose logs -f+ ;;+ all|*)+ print_info "Showing backend logs (Ctrl+C to switch to frontend)..."+ echo ""+ # Show both in split view isn't easy in bash, so show backend first+ journalctl -u $BACKEND_SERVICE -n 50 --no-pager+ echo ""+ print_info "Showing frontend logs..."+ echo ""+ cd "$INSTALL_DIR"+ docker compose logs --tail=50+ echo ""+ print_info "For live logs, use: serverkit logs backend OR serverkit logs frontend"+ ;;+ esac}cmd_update() {+ check_rootcheck_installed- cd "$INSTALL_DIR"+ print_header+ echo ""print_info "Updating ServerKit..."+ cd "$INSTALL_DIR"++ # Store current version+ CURRENT_VERSION=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")++ # Stop services+ print_info "Stopping services..."+ systemctl stop $BACKEND_SERVICE || true+ docker compose down || true+# Pull latest changes- if [ -d ".git" ]; then- git pull- fi+ print_info "Pulling latest changes..."+ git fetch origin+ git reset --hard origin/main++ NEW_VERSION=$(git rev-parse --short HEAD)- # Rebuild and restart+ # Update Python dependencies+ print_info "Updating Python dependencies..."+ source "$VENV_DIR/bin/activate"+ pip install -r "$INSTALL_DIR/backend/requirements.txt" --quiet++ # Rebuild frontend+ print_info "Rebuilding frontend..."docker compose build++ # Reload systemd in case service file changed+ systemctl daemon-reload++ # Restart services+ print_info "Starting services..."+ systemctl start $BACKEND_SERVICEdocker compose up -d- print_success "ServerKit updated"+ sleep 5++ echo ""+ print_success "ServerKit updated!"+ echo " Previous version: $CURRENT_VERSION"+ echo " Current version: $NEW_VERSION"+ echo ""+ cmd_status_brief}cmd_uninstall() {+ check_rootprint_headerecho ""print_warning "This will remove ServerKit and all data!"@@ -283,12 +280,21 @@ cmd_uninstall() {echoif [[ $REPLY =~ ^[Yy]$ ]]; then- if [ -d "$INSTALL_DIR" ]; then- cd "$INSTALL_DIR"- docker compose down -v 2>/dev/null || true- cd /- sudo rm -rf "$INSTALL_DIR"- fi+ print_info "Stopping services..."+ systemctl stop $BACKEND_SERVICE 2>/dev/null || true+ systemctl disable $BACKEND_SERVICE 2>/dev/null || true++ cd "$INSTALL_DIR" 2>/dev/null && docker compose down -v 2>/dev/null || true++ print_info "Removing files..."+ rm -f /etc/systemd/system/serverkit.service+ rm -f /usr/local/bin/serverkit+ rm -rf "$INSTALL_DIR"+ rm -rf /var/log/serverkit+ rm -rf /var/lib/serverkit++ systemctl daemon-reload+print_success "ServerKit uninstalled"fi}@@ -337,20 +343,30 @@ cmd_init_db() {cmd_backup_db() {check_installed- cd "$INSTALL_DIR"- BACKUP_FILE="backup/serverkit-$(date +%Y%m%d-%H%M%S).db"- mkdir -p backup- docker cp $CONTAINER_NAME:/app/instance/serverkit.db "$BACKUP_FILE"- print_success "Database backed up to $BACKUP_FILE"+ BACKUP_DIR="$INSTALL_DIR/backups"+ BACKUP_FILE="$BACKUP_DIR/serverkit-$(date +%Y%m%d-%H%M%S).db"+ DB_FILE="$INSTALL_DIR/backend/instance/serverkit.db"++ mkdir -p "$BACKUP_DIR"++ if [ -f "$DB_FILE" ]; then+ cp "$DB_FILE" "$BACKUP_FILE"+ print_success "Database backed up to $BACKUP_FILE"+ else+ print_error "Database file not found: $DB_FILE"+ exit 1+ fi}cmd_restore_db() {+ check_rootcheck_installed- cd "$INSTALL_DIR"+ BACKUP_DIR="$INSTALL_DIR/backups"+ DB_FILE="$INSTALL_DIR/backend/instance/serverkit.db"if [ -z "$1" ]; thenecho "Available backups:"- ls -la backup/*.db 2>/dev/null || echo "No backups found"+ ls -la "$BACKUP_DIR"/*.db 2>/dev/null || echo "No backups found"echo ""read -p "Enter backup file path: " BACKUP_FILEelse@@ -367,34 +383,34 @@ cmd_restore_db() {echoif [[ $REPLY =~ ^[Yy]$ ]]; then- docker cp "$BACKUP_FILE" $CONTAINER_NAME:/app/instance/serverkit.db- docker compose restart backend+ # Stop backend before restore+ systemctl stop $BACKEND_SERVICE++ cp "$BACKUP_FILE" "$DB_FILE"++ # Restart backend+ systemctl start $BACKEND_SERVICE+print_success "Database restored"fi}cmd_generate_keys() {- check_dockerprint_headerecho ""echo "Add these to your .env file:"echo ""- SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))" 2>/dev/null || openssl rand -hex 32)- JWT_SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))" 2>/dev/null || openssl rand -hex 32)+ SECRET_KEY=$(openssl rand -hex 32)+ JWT_SECRET_KEY=$(openssl rand -hex 32)echo "SECRET_KEY=$SECRET_KEY"echo "JWT_SECRET_KEY=$JWT_SECRET_KEY"echo ""}-cmd_shell() {- check_installed- docker exec -it $CONTAINER_NAME /bin/bash-}-cmd_config() {check_installed${EDITOR:-nano} "$INSTALL_DIR/.env"- print_info "Restart ServerKit to apply changes: serverkit restart"+ print_info "Restart ServerKit to apply changes: sudo serverkit restart"}# Main@@ -402,9 +418,6 @@ case "${1:-help}" inhelp|--help|-h)cmd_help;;- install)- cmd_install- ;;start)cmd_start;;@@ -459,9 +472,6 @@ case "${1:-help}" ingenerate-keys)cmd_generate_keys;;- shell)- cmd_shell- ;;config)cmd_config;;diff --git a/serverkit-backend.service b/serverkit-backend.servicenew file mode 100644index 00000000..87662198--- /dev/null+++ b/serverkit-backend.service@@ -0,0 +1,30 @@+[Unit]+Description=ServerKit Backend API+After=network.target docker.service+Wants=docker.service++[Service]+Type=simple+User=root+Group=root+WorkingDirectory=/opt/serverkit/backend+Environment="PATH=/opt/serverkit/venv/bin:/usr/local/bin:/usr/bin:/bin"+Environment="FLASK_ENV=production"+EnvironmentFile=/opt/serverkit/.env+ExecStart=/opt/serverkit/venv/bin/gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 -b 127.0.0.1:5000 --timeout 120 --access-logfile /var/log/serverkit/access.log --error-logfile /var/log/serverkit/error.log run:app+ExecReload=/bin/kill -HUP $MAINPID+Restart=always+RestartSec=5++# Security settings (while still allowing system management)+NoNewPrivileges=no+ProtectSystem=no+ProtectHome=no++# Logging+StandardOutput=journal+StandardError=journal+SyslogIdentifier=serverkit++[Install]+WantedBy=multi-user.target