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.

Refactor installer and uninstaller scripts

Juan Denis6e9145495d9e
diff --git a/.claude/skills/code-review/SKILL.md b/.claude/skills/code-review/SKILL.md
deleted file mode 100644
index 3aa49c32..00000000
--- a/.claude/skills/code-review/SKILL.md
+++ /dev/null
@@ -1,165 +0,0 @@
----
-name: code-review
-description: Run a multi-perspective code review on recent changes using specialized reviewer personas. Each reviewer focuses on their domain — security, ops, cross-platform, API design, frontend, and performance. Produces a dated review report.
-argument-hint: "[file, directory, or git range]"
----
-
-# Code Review — Multi-Perspective Audit
-
-Review code from the perspective of 6 specialized reviewers, each with their own focus area. Produces a structured report in `.reviews/`.
-
-## Scope
-
-Determine what to review based on the argument:
-
-- **No argument**: Review all uncommitted changes (`git diff` + `git diff --cached`)
-- **A file or directory path**: Review that specific path
-- **A git range** (e.g., `main..HEAD`, `HEAD~3`): Review that commit range
-- **`last`**: Review the last commit (`HEAD~1..HEAD`)
-
-## The Reviewers
-
-### Mara — Security
-
-Focuses on authentication, authorization, and injection vectors.
-
-- JWT handling: token validation, expiry, refresh flows
-- SQL injection: raw queries, unparameterized input
-- XSS: unsanitized user input rendered in responses or frontend
-- CORS misconfigurations
-- Path traversal in file operations (`../` in user-supplied paths)
-- Secrets in code (API keys, passwords, hardcoded tokens)
-- Missing `@jwt_required()` on API routes that need auth
-- CSRF protection gaps
-
-### Raj — Ops & Infrastructure
-
-Focuses on subprocess calls, privilege escalation, and system operations.
-
-- Missing `sudo` on privileged commands (systemctl, firewall-cmd, ufw, certbot, nginx)
-- Raw `subprocess.run()` that should use `run_privileged()`, `ServiceControl`, or `PackageManager`
-- Missing error handling on subprocess calls (unchecked `returncode`, no try/except)
-- Hardcoded paths that assume specific filesystem layout
-- Logging gaps: operations that modify system state without logging what they did
-- Service restart ordering issues
-
-### Sol — Cross-Platform & Containers
-
-Focuses on portability across distros and container environments.
-
-- Distro-specific commands (`dpkg`, `apt`, `rpm`, `dnf`) without `FileNotFoundError` handling
-- Unguarded `/proc/` and `/sys/` reads that fail in LXC/containers
-- `psutil` calls that return `None` in containers (`disk_io_counters`, `sensors_temperatures`) used without null checks
-- Docker socket assumptions without availability checks
-- Firewall commands that need `CAP_NET_ADMIN` (dropped in unprivileged LXC)
-- Hardcoded `/dev/` device paths
-- Assumptions about init system (systemd vs others)
-- Package manager detection that only checks one family
-
-### Kai — API Design
-
-Focuses on REST conventions, error handling, and request/response patterns.
-
-- Inconsistent error response format (should always be `{'error': 'message'}, status_code`)
-- Missing input validation on request body fields
-- Wrong HTTP status codes (e.g., 200 on error, 404 when it should be 403)
-- Missing pagination on list endpoints
-- Endpoints that return too much data (no field filtering)
-- Inconsistent URL naming (`/api/v1/` prefix, plural nouns)
-- Missing rate limiting on sensitive endpoints (login, password reset)
-- N+1 query patterns in endpoints that return lists
-
-### Lena — Frontend
-
-Focuses on React patterns, UX quality, and style consistency.
-
-- Class components or non-hook patterns (should be functional + hooks only)
-- Inline styles (should use LESS with design system variables)
-- Missing loading states or error handling on data fetches
-- Accessibility gaps: missing alt text, aria labels, keyboard navigation
-- Hardcoded strings that should come from the API or config
-- Memory leaks: missing cleanup in `useEffect`
-- Props drilling beyond 3 levels (should use Context)
-- Missing key props in lists
-- Console.log left in production code
-
-### Omar — Performance
-
-Focuses on efficiency, caching, and resource usage.
-
-- Synchronous blocking calls that should be async (especially subprocess calls in request handlers)
-- Missing database indexes on frequently queried columns
-- Unbounded queries: `SELECT *` without `LIMIT` or pagination
-- Repeated identical subprocess calls that could be cached
-- Large file reads loaded entirely into memory
-- Frontend: unnecessary re-renders, missing `useMemo`/`useCallback` where expensive
-- Missing `timeout` on subprocess calls or external HTTP requests
-- Socket.IO events that broadcast too frequently
-
-## How to Review
-
-1. Determine the scope from `$ARGUMENTS` and read all relevant code
-2. For each reviewer, analyze the code **only through their lens** — don't overlap
-3. Rate each finding:
- - **Fix** — Bug, vulnerability, or will break in production. Must address.
- - **Improve** — Works but suboptimal. Should address.
- - **Note** — Observation or suggestion. Nice to know, no action needed.
-4. Collect all findings
-
-## Report
-
-Create the `.reviews/` directory if it doesn't exist. Write to `.reviews/YYYY-MM-DD-review.md` (use today's date). If a file for today exists, append a counter: `YYYY-MM-DD-2-review.md`.
-
-```markdown
-# Code Review — YYYY-MM-DD
-
-**Scope:** <what was reviewed>
-**Files reviewed:** N
-
-## Summary
-
-| Reviewer | Focus | Fix | Improve | Note |
-|----------|-------|-----|---------|------|
-| Mara | Security | N | N | N |
-| Raj | Ops | N | N | N |
-| Sol | Cross-Platform | N | N | N |
-| Kai | API Design | N | N | N |
-| Lena | Frontend | N | N | N |
-| Omar | Performance | N | N | N |
-| **Total** | | **N** | **N** | **N** |
-
-## Findings
-
-### Mara — Security
-
-#### [Fix] Short description
-`file_path:line_number`
-Explanation of the issue and why it matters.
-**Suggested fix:** What to change.
-
-#### [Improve] Short description
-...
-
-### Raj — Ops & Infrastructure
-...
-
-### Sol — Cross-Platform & Containers
-...
-
-### Kai — API Design
-...
-
-### Lena — Frontend
-...
-
-### Omar — Performance
-...
-
-## Verdict
-
-**PASS** — No Fix-severity findings. Ship it.
-or
-**NEEDS WORK** — N Fix-severity findings must be addressed before merging.
-```
-
-After writing the report, print the summary table and verdict to the user. If there are Fix-severity findings, ask if they want you to address them now.
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
new file mode 100644
index 00000000..9e7d57a6
--- /dev/null
+++ b/CONTRIBUTORS.md
@@ -0,0 +1,14 @@
+# Contributors
+
+Thanks to everyone who has contributed to ServerKit!
+
+## Core
+
+- **Juan Denis** ([@jhd3197](https://github.com/jhd3197)) — Creator and maintainer
+
+## Contributors
+
+| Who | Contribution | PR |
+|-----|-------------|-----|
+| **Rapeepan Moonthai** ([@rapeeza1598](https://github.com/rapeeza1598)) | Fedora support for install script (DNF + SELinux) | [#31](https://github.com/jhd3197/ServerKit/pull/31) |
+| **Piya Miang-Lae** ([@Piya-Boy](https://github.com/Piya-Boy)) | Backups storage provider | [#26](https://github.com/jhd3197/ServerKit/pull/26) |
diff --git a/install.sh b/install.sh
index dc72ac27..64cf8989 100644
--- a/install.sh
+++ b/install.sh
@@ -2,11 +2,21 @@
#
# ServerKit Quick Install Script for Ubuntu/Debian/Fedora
#
+# Architecture:
+# - Backend: Runs directly on host (for full system access)
+# - Frontend: Runs in Docker (nginx serving static files)
+#
+# Usage: curl -fsSL https://serverkit.ai/install.sh | bash
+#
set -e
+# Safety: Move to a valid directory first
+# Prevents "getcwd: cannot access parent directories" error
+# when running from a deleted directory (e.g., after uninstall)
cd /tmp 2>/dev/null || cd / || true
+# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
@@ -26,368 +36,425 @@ PYTHON_BIN=""
SAFE_MODE=false
print_header() {
-echo -e "${BLUE}"
-echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
-echo " ServerKit Installer"
-echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
-echo -e "${NC}"
+ 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}"; }
-
-version_ge(){ printf '%s\n%s' "$2" "$1" | sort -C -V; }
-version_le(){ printf '%s\n%s' "$1" "$2" | sort -C -V; }
-
-detect_python(){
-
-if command -v python3 &>/dev/null; then
- PY_VER=$(python3 -c 'import sys;print(".".join(map(str,sys.version_info[:2])))')
-
- if version_ge "$PY_VER" "$PYTHON_MIN" && version_le "$PY_VER" "$PYTHON_MAX"; then
- PYTHON_BIN="python3"
- print_success "Using system Python $PY_VER"
- return
+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}"; }
+
+version_ge() { printf '%s\n%s' "$2" "$1" | sort -C -V; }
+version_le() { printf '%s\n%s' "$1" "$2" | sort -C -V; }
+
+# Detect supported Python (3.11-3.12)
+detect_python() {
+ if command -v python3 &>/dev/null; then
+ PY_VER=$(python3 -c 'import sys;print(".".join(map(str,sys.version_info[:2])))')
+ if version_ge "$PY_VER" "$PYTHON_MIN" && version_le "$PY_VER" "$PYTHON_MAX"; then
+ PYTHON_BIN="python3"
+ print_success "Using system Python $PY_VER"
+ return
+ fi
fi
-fi
-
-print_warning "System Python not supported ($PYTHON_MIN-$PYTHON_MAX)"
+ print_warning "System Python not in supported range ($PYTHON_MIN-$PYTHON_MAX)"
}
-check_ram(){
-
-RAM=$(free -m | awk '/Mem:/ {print $2}')
-
-if [ "$RAM" -le 700 ]; then
-SAFE_MODE=true
-print_warning "Low RAM detected (${RAM}MB) → enabling VPS Safe Mode"
-fi
-
+# Check RAM and enable safe mode for small VPS
+check_ram() {
+ RAM=$(free -m | awk '/Mem:/ {print $2}')
+ if [ "$RAM" -le 700 ]; then
+ SAFE_MODE=true
+ print_warning "Low RAM detected (${RAM}MB) → enabling VPS Safe Mode"
+ fi
}
-setup_swap(){
-
-SWAP_TOTAL=$(free -m | awk '/Swap:/ {print $2}')
-
-if [ "$SWAP_TOTAL" -lt 512 ]; then
-
-print_info "Creating swap (1GB)"
-
-if [ ! -f /swapfile ]; then
-fallocate -l 1G /swapfile 2>/dev/null || dd if=/dev/zero of=/swapfile bs=1M count=1024
-chmod 600 /swapfile
-mkswap /swapfile >/dev/null
-fi
-
-swapon /swapfile || true
-
-print_success "Swap enabled"
-
-fi
-
+# Create swap if system has very little
+setup_swap() {
+ SWAP_TOTAL=$(free -m | awk '/^Swap:/ {print $2}')
+ if [ "$SWAP_TOTAL" -lt 512 ]; then
+ print_info "Creating swap space (1GB)..."
+ if [ ! -f /swapfile ]; then
+ fallocate -l 1G /swapfile 2>/dev/null || dd if=/dev/zero of=/swapfile bs=1M count=1024 status=none
+ chmod 600 /swapfile
+ mkswap /swapfile >/dev/null
+ fi
+ swapon /swapfile 2>/dev/null || true
+ print_success "Swap enabled"
+ fi
}
print_header
+# Check if running as root
if [ "$EUID" -ne 0 ]; then
-print_error "Please run as root (sudo)"
-exit 1
+ print_error "Please run as root (sudo)"
+ exit 1
fi
-OS_FAMILY="unknown"
+# Enable low-RAM protections early (needs root for swap)
+check_ram
+setup_swap
+# Detect OS family
+OS_FAMILY="unknown"
if [ -f /etc/os-release ]; then
-. /etc/os-release
-
-if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then
-OS_FAMILY="debian"
-elif [ "$ID" = "fedora" ]; then
-OS_FAMILY="fedora"
+ . /etc/os-release
+ if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then
+ OS_FAMILY="debian"
+ elif [ "$ID" = "fedora" ]; then
+ OS_FAMILY="fedora"
+ else
+ print_warning "Unsupported OS ($ID). This script is designed for Ubuntu/Debian/Fedora."
+ fi
else
-print_warning "Unknown OS"
-fi
+ print_warning "Cannot detect OS. Proceeding with caution."
fi
+echo ""
print_info "Installing system dependencies..."
if [ "$OS_FAMILY" = "debian" ] || [ "$OS_FAMILY" = "unknown" ]; then
+ # Configure needrestart for non-interactive mode (Ubuntu 22.04+)
+ # This prevents the "Which services should be restarted?" dialog
+ # and avoids dpkg lock issues during automated installs
+ export NEEDRESTART_MODE=a
+ export DEBIAN_FRONTEND=noninteractive
+
+ # Also configure needrestart.conf if it exists for future apt operations
+ if [ -f /etc/needrestart/needrestart.conf ]; then
+ sed -i "s/#\$nrconf{restart} = 'i';/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf 2>/dev/null || true
+ fi
-export NEEDRESTART_MODE=a
-export DEBIAN_FRONTEND=noninteractive
-
-apt-get update
-
-apt-get install -y \
-python3 \
-python3-pip \
-python3-venv \
-python3-dev \
-git \
-curl \
-build-essential \
-libffi-dev \
-libssl-dev \
-iproute2 \
-procps
-
-detect_python
-
-if [ -z "$PYTHON_BIN" ]; then
-
-print_info "Installing Python 3.12..."
-
-apt-get install -y \
-python3.12 \
-python3.12-venv \
-python3.12-dev
-
-PYTHON_BIN="python3.12"
-
-fi
+ apt-get update
+
+ apt-get install -y \
+ python3 \
+ python3-pip \
+ python3-venv \
+ python3-dev \
+ git \
+ curl \
+ build-essential \
+ libffi-dev \
+ libssl-dev \
+ iproute2 \
+ procps
+
+ detect_python
+
+ # If system Python is out of supported range, install 3.12
+ if [ -z "$PYTHON_BIN" ]; then
+ print_info "Installing Python 3.12..."
+ apt-get install -y \
+ python3.12 \
+ python3.12-venv \
+ python3.12-dev
+ PYTHON_BIN="python3.12"
+ fi
elif [ "$OS_FAMILY" = "fedora" ]; then
-
-dnf update -y
-
-dnf install -y \
-python3 \
-python3-pip \
-git \
-curl \
-gcc \
-gcc-c++ \
-make \
-libffi-devel \
-openssl-devel \
-python3-devel \
-iproute \
-procps-ng
-
-detect_python
-
-if [ -z "$PYTHON_BIN" ]; then
-
-print_info "Installing Python 3.12..."
-
-dnf install -y \
-python3.12 \
-python3.12-devel
-
-PYTHON_BIN="python3.12"
-
-fi
-
+ dnf update -y
+
+ dnf install -y \
+ python3 \
+ python3-pip \
+ python3-devel \
+ git \
+ curl \
+ gcc \
+ gcc-c++ \
+ make \
+ libffi-devel \
+ openssl-devel \
+ python3-devel \
+ iproute \
+ procps-ng
+
+ detect_python
+
+ if [ -z "$PYTHON_BIN" ]; then
+ print_info "Installing Python 3.12..."
+ dnf install -y \
+ python3.12 \
+ python3.12-devel
+ PYTHON_BIN="python3.12"
+ fi
fi
print_success "System dependencies installed"
+# Install Docker if not present
if ! command -v docker &> /dev/null; then
-
-print_info "Installing Docker..."
-
-curl -fsSL https://get.docker.com | sh
-
-systemctl enable docker
-systemctl start docker
-
-print_success "Docker installed"
-
+ print_info "Installing Docker..."
+ curl -fsSL https://get.docker.com | sh
+ systemctl enable docker
+ systemctl start docker
+ print_success "Docker installed"
else
-
-print_success "Docker already installed"
-
+ print_success "Docker already installed"
fi
+# Install Docker Compose plugin if not present
if ! docker compose version &> /dev/null; then
-
-print_info "Installing Docker Compose..."
-
-if [ "$OS_FAMILY" = "fedora" ]; then
-dnf install -y docker-compose-plugin
-else
-apt-get install -y docker-compose-plugin
-fi
-
-print_success "Docker Compose installed"
-
+ print_info "Installing Docker Compose..."
+ if [ "$OS_FAMILY" = "fedora" ]; then
+ dnf install -y docker-compose-plugin
+ else
+ apt-get install -y docker-compose-plugin
+ fi
+ print_success "Docker Compose installed"
else
-
-print_success "Docker Compose already installed"
-
+ print_success "Docker Compose already installed"
fi
+# Install Node.js for frontend build (builds on host to avoid Docker memory issues)
if ! command -v node &> /dev/null; then
-
-print_info "Installing Node.js..."
-
-if [ "$OS_FAMILY" = "fedora" ]; then
-curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
-dnf install -y nodejs
-else
-curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
-apt-get install -y nodejs
-
-fi
-
-print_success "Node.js $(node --version) installed"
-
+ print_info "Installing Node.js..."
+ if [ "$OS_FAMILY" = "fedora" ]; then
+ curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
+ dnf install -y nodejs
+ else
+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
+ apt-get install -y nodejs
+ fi
+ print_success "Node.js $(node --version) installed"
else
-
-print_success "Node.js $(node --version) already installed"
-
+ print_success "Node.js $(node --version) already installed"
fi
+# Clone or update repository
print_info "Installing ServerKit to $INSTALL_DIR..."
if [ -d "$INSTALL_DIR" ]; then
-
-print_warning "Directory exists, updating..."
-
-cd "$INSTALL_DIR"
-git fetch origin
-git reset --hard origin/main
-
+ print_warning "Directory exists, updating..."
+ cd "$INSTALL_DIR"
+ git fetch origin
+ git reset --hard origin/main
else
-
-git clone https://github.com/jhd3197/serverkit.git "$INSTALL_DIR"
-cd "$INSTALL_DIR"
-
+ git clone https://github.com/jhd3197/serverkit.git "$INSTALL_DIR"
+ cd "$INSTALL_DIR"
fi
+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"
+mkdir -p /etc/serverkit/templates
+mkdir -p /var/serverkit/apps
+
+# Copy bundled templates to system directory
+print_info "Installing app templates..."
+if [ -d "$INSTALL_DIR/backend/templates" ]; then
+ 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
+ print_success "Installed $(ls /etc/serverkit/templates/*.yaml 2>/dev/null | wc -l) app templates"
+fi
+# Set up Python virtual environment
print_info "Setting up Python virtual environment..."
-
-print_info "Using Python binary: $PYTHON_BIN"
-
-$PYTHON_BIN --version
-
$PYTHON_BIN -m venv "$VENV_DIR"
-
source "$VENV_DIR/bin/activate"
+# Install Python dependencies
print_info "Installing Python dependencies..."
-
+pip install --upgrade pip
if [ "$SAFE_MODE" = true ]; then
-pip install --upgrade pip --no-cache-dir
-pip install --no-cache-dir -r "$INSTALL_DIR/backend/requirements.txt"
+ pip install --no-cache-dir -r "$INSTALL_DIR/backend/requirements.txt"
else
-pip install --upgrade pip
-pip install -r "$INSTALL_DIR/backend/requirements.txt"
+ pip install -r "$INSTALL_DIR/backend/requirements.txt"
fi
-
pip install gunicorn gevent gevent-websocket
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)
-print_info "Generating configuration..."
+ cat > "$INSTALL_DIR/.env" << EOF
+# ServerKit Configuration
+# Generated on $(date)
-SECRET_KEY=$(openssl rand -hex 32)
-JWT_SECRET_KEY=$(openssl rand -hex 32)
-
-cat > "$INSTALL_DIR/.env" << EOF
+# Security Keys (auto-generated, keep secret!)
SECRET_KEY=$SECRET_KEY
JWT_SECRET_KEY=$JWT_SECRET_KEY
+
+# 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
+
+# Ports
PORT=80
SSL_PORT=443
+
+# Environment
FLASK_ENV=production
EOF
+ print_success "Configuration generated"
+else
+ print_warning ".env already exists, keeping existing configuration"
fi
-print_info "Installing systemd service..."
+# 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 "$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
+# 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"
-print_info "Installing nginx..."
-
+# Install and configure host nginx as reverse proxy
+print_info "Setting up nginx reverse proxy..."
if [ "$OS_FAMILY" = "fedora" ]; then
-dnf install -y nginx
+ dnf install -y nginx
else
-apt-get install -y nginx
+ apt-get install -y nginx
fi
-systemctl enable nginx
-systemctl start nginx
+# Stop nginx and remove default site
+systemctl stop nginx 2>/dev/null || true
+rm -f /etc/nginx/sites-enabled/default
-print_success "Nginx installed"
+# Ensure sites directories exist
+mkdir -p /etc/nginx/sites-available
+mkdir -p /etc/nginx/sites-enabled
-print_info "Building frontend..."
+# 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
-cd "$INSTALL_DIR/frontend"
+# 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/
+
+# Copy site template
+cp "$INSTALL_DIR/nginx/sites-available/example.conf.template" /etc/nginx/sites-available/
+
+# Configure SELinux to allow nginx reverse proxying (Fedora)
+if [ "$OS_FAMILY" = "fedora" ] && command -v setsebool &> /dev/null; then
+ setsebool -P httpd_can_network_connect 1 2>/dev/null || true
+fi
+
+print_success "Nginx proxy configured"
+
+# Clean up Docker to prevent issues
+print_info "Cleaning up Docker..."
+docker network prune -f 2>/dev/null || true
+docker container prune -f 2>/dev/null || true
-npm ci --prefer-offline
+# Ensure swap exists for low-RAM VPS servers (Vite build needs ~512MB+)
+setup_swap
+# Build frontend on host (avoids Docker memory overhead on low-RAM VPS)
+print_info "Building frontend..."
+cd "$INSTALL_DIR/frontend"
+npm ci --prefer-offline 2>&1 | tail -1
NODE_OPTIONS="--max-old-space-size=1024" npm run build
+print_success "Frontend built"
+# Package frontend into nginx container
+print_info "Building frontend container..."
cd "$INSTALL_DIR"
-
docker compose build
+print_info "Starting services..."
+
+# Start backend (systemd)
systemctl start serverkit
+# Start frontend (Docker)
docker compose up -d
+# Start nginx
systemctl start nginx
+systemctl enable nginx
-sleep 8
+# Wait for services to start
+print_info "Waiting for services to start..."
+sleep 10
+# Health check
+echo ""
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"
+ BACKEND_OK=true
+ print_success "Backend is running"
else
-print_error "Backend health check failed"
+ 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"
+ FRONTEND_OK=true
+ print_success "Frontend is running"
else
-print_error "Frontend health check failed"
+ print_error "Frontend health check failed"
fi
echo ""
-
if [ "$BACKEND_OK" = true ] && [ "$FRONTEND_OK" = true ]; then
-
-echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
-echo -e "${GREEN} Installation Complete!${NC}"
-echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
-
-echo ""
-echo "ServerKit running at http://localhost"
-echo ""
-echo "Create admin:"
-echo "serverkit create-admin"
-echo ""
-echo "Status:"
-echo "serverkit status"
-echo ""
-
+ # Track successful install
+ INSTALLED_VERSION=$(cat "$INSTALL_DIR/VERSION" 2>/dev/null | tr -d '\n\r ')
+ curl -s "https://serverkit.ai/track/install?v=${INSTALLED_VERSION}" >/dev/null 2>&1 || true
+
+ echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ echo -e "${GREEN} Installation Complete!${NC}"
+ echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ echo ""
+ echo "ServerKit is now running at: http://localhost"
+ echo ""
+ echo "Quick Start:"
+ echo " 1. Create admin user: serverkit create-admin"
+ echo " 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 --project-directory $INSTALL_DIR [up|down]"
+ echo ""
+ echo "For all commands: serverkit help"
+ echo ""
else
-
-echo -e "${RED}Installation may have issues${NC}"
-
+ echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ echo -e "${RED} Installation may have issues${NC}"
+ echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ echo ""
+ echo "Troubleshooting:"
+ echo " Backend logs: journalctl -u serverkit -f"
+ echo " Frontend logs: docker compose --project-directory $INSTALL_DIR logs -f"
+ echo ""
fi
diff --git a/uninstall.sh b/uninstall.sh
index 3edb07b8..c2440d2b 100644
--- a/uninstall.sh
+++ b/uninstall.sh
@@ -28,25 +28,25 @@ NC='\033[0m'
########################################
print_header() {
-echo -e "${BLUE}"
-echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
-echo " ServerKit Uninstaller"
-echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
-echo -e "${NC}"
+ echo -e "${BLUE}"
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+ echo " ServerKit Uninstaller"
+ 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_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}"; }
########################################
# Root check
########################################
if [[ $EUID -ne 0 ]]; then
-print_error "Please run as root (sudo)"
-exit 1
+ print_error "Please run as root (sudo)"
+ exit 1
fi
print_header
@@ -59,8 +59,8 @@ echo
read -p "Remove ServerKit completely? (y/N): " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
-print_warning "Uninstall cancelled"
-exit 0
+ print_warning "Uninstall cancelled"
+ exit 0
fi
########################################
@@ -80,7 +80,11 @@ print_success "Backend service stopped"
print_info "Stopping Docker containers"
-docker compose -C "$INSTALL_DIR" down --remove-orphans 2>/dev/null || true
+if command -v docker &>/dev/null && [ -d "$INSTALL_DIR" ]; then
+ docker compose --project-directory "$INSTALL_DIR" down --remove-orphans 2>/dev/null || true
+else
+ print_warning "Docker or install directory not found, skipping container cleanup"
+fi
print_success "Containers removed"
@@ -126,8 +130,10 @@ print_success "Installation directory removed"
print_info "Removing data directory"
rm -rf "$DATA_DIR"
+rm -rf /etc/serverkit
+rm -rf /var/serverkit
-print_success "Data directory removed"
+print_success "Data directories removed"
########################################
# Remove logs
@@ -149,6 +155,12 @@ rm -f /usr/local/bin/serverkit
print_success "CLI removed"
+########################################
+# Track uninstall
+########################################
+
+curl -s "https://serverkit.ai/track/uninstall" >/dev/null 2>&1 || true
+
########################################
# Finish
########################################
@@ -161,4 +173,4 @@ echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━
echo
echo "Uninstall log:"
echo "$LOG_FILE"
-echo
\ No newline at end of file
+echo