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.

Add ServerKit CLI, install script, and deployment improvements

Juan Denisc1d60f112f8c
diff --git a/.env.example b/.env.example
new file mode 100644
index 00000000..d5a8ede9
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,22 @@
+# ServerKit Configuration
+# Copy this file to .env and customize
+
+# Security Keys (REQUIRED - generate with: serverkit generate-keys)
+SECRET_KEY=your-secret-key-here
+JWT_SECRET_KEY=your-jwt-secret-key-here
+
+# Database
+# SQLite (default):
+DATABASE_URL=sqlite:///serverkit.db
+# PostgreSQL:
+# DATABASE_URL=postgresql://user:password@localhost:5432/serverkit
+
+# CORS - your domain (comma-separated for multiple)
+CORS_ORIGINS=http://localhost
+
+# Ports
+PORT=80
+SSL_PORT=443
+
+# Environment
+FLASK_ENV=production
diff --git a/README.md b/README.md
index 28be92bc..4617cb15 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ ServerKit is a lightweight, modern server control panel for managing web applica
```bash
# Clone the repository
-git clone https://github.com/yourusername/ServerKit.git
+git clone https://github.com/jhd3197/ServerKit.git
cd ServerKit
# Backend setup
diff --git a/backend/cli.py b/backend/cli.py
new file mode 100644
index 00000000..8a819a95
--- /dev/null
+++ b/backend/cli.py
@@ -0,0 +1,188 @@
+#!/usr/bin/env python3
+"""ServerKit CLI - Administrative commands for ServerKit."""
+
+import click
+import secrets
+import sys
+from werkzeug.security import generate_password_hash
+
+from app import create_app, db
+from app.models import User
+
+
+def cli():
+ """ServerKit administrative CLI."""
+ pass
+
+
[email protected]('--email', prompt=True, help='Admin email address')
[email protected]('--username', prompt=True, help='Admin username')
[email protected]('--password', prompt=True, hide_input=True, confirmation_prompt=True, help='Admin password')
+def create_admin(email, username, password):
+ """Create a new admin user."""
+ app = create_app()
+ with app.app_context():
+ # Check if user already exists
+ if User.query.filter((User.email == email) | (User.username == username)).first():
+ click.echo(click.style('Error: User with this email or username already exists.', fg='red'))
+ sys.exit(1)
+
+ user = User(
+ email=email,
+ username=username,
+ role='admin',
+ is_active=True
+ )
+ user.set_password(password)
+ db.session.add(user)
+ db.session.commit()
+
+ click.echo(click.style(f'Admin user "{username}" created successfully!', fg='green'))
+
+
[email protected]('--email', prompt=True, help='User email address')
[email protected]('--password', prompt=True, hide_input=True, confirmation_prompt=True, help='New password')
+def reset_password(email, password):
+ """Reset a user's password."""
+ app = create_app()
+ with app.app_context():
+ user = User.query.filter_by(email=email).first()
+ if not user:
+ click.echo(click.style(f'Error: User with email "{email}" not found.', fg='red'))
+ sys.exit(1)
+
+ user.set_password(password)
+ user.failed_login_count = 0
+ user.locked_until = None
+ db.session.commit()
+
+ click.echo(click.style(f'Password reset successfully for "{user.username}"!', fg='green'))
+
+
[email protected]('--email', prompt=True, help='User email address')
+def unlock_user(email):
+ """Unlock a locked user account."""
+ app = create_app()
+ with app.app_context():
+ user = User.query.filter_by(email=email).first()
+ if not user:
+ click.echo(click.style(f'Error: User with email "{email}" not found.', fg='red'))
+ sys.exit(1)
+
+ user.failed_login_count = 0
+ user.locked_until = None
+ db.session.commit()
+
+ click.echo(click.style(f'User "{user.username}" unlocked successfully!', fg='green'))
+
+
[email protected]('--email', prompt=True, help='User email address')
+def make_admin(email):
+ """Promote a user to admin role."""
+ app = create_app()
+ with app.app_context():
+ user = User.query.filter_by(email=email).first()
+ if not user:
+ click.echo(click.style(f'Error: User with email "{email}" not found.', fg='red'))
+ sys.exit(1)
+
+ user.role = 'admin'
+ db.session.commit()
+
+ click.echo(click.style(f'User "{user.username}" is now an admin!', fg='green'))
+
+
[email protected]('--email', prompt=True, help='User email address')
+def deactivate_user(email):
+ """Deactivate a user account."""
+ app = create_app()
+ with app.app_context():
+ user = User.query.filter_by(email=email).first()
+ if not user:
+ click.echo(click.style(f'Error: User with email "{email}" not found.', fg='red'))
+ sys.exit(1)
+
+ user.is_active = False
+ db.session.commit()
+
+ click.echo(click.style(f'User "{user.username}" has been deactivated.', fg='yellow'))
+
+
[email protected]('--email', prompt=True, help='User email address')
+def activate_user(email):
+ """Activate a user account."""
+ app = create_app()
+ with app.app_context():
+ user = User.query.filter_by(email=email).first()
+ if not user:
+ click.echo(click.style(f'Error: User with email "{email}" not found.', fg='red'))
+ sys.exit(1)
+
+ user.is_active = True
+ db.session.commit()
+
+ click.echo(click.style(f'User "{user.username}" has been activated.', fg='green'))
+
+
+def list_users():
+ """List all users."""
+ app = create_app()
+ with app.app_context():
+ users = User.query.all()
+
+ if not users:
+ click.echo('No users found.')
+ return
+
+ click.echo(f"\n{'ID':<5} {'Username':<20} {'Email':<30} {'Role':<10} {'Active':<8} {'Locked':<8}")
+ click.echo('-' * 85)
+
+ for user in users:
+ locked = 'Yes' if user.is_locked else 'No'
+ active = 'Yes' if user.is_active else 'No'
+ click.echo(f"{user.id:<5} {user.username:<20} {user.email:<30} {user.role:<10} {active:<8} {locked:<8}")
+
+ click.echo(f"\nTotal: {len(users)} user(s)")
+
+
+def generate_keys():
+ """Generate secure SECRET_KEY and JWT_SECRET_KEY."""
+ secret_key = secrets.token_hex(32)
+ jwt_secret_key = secrets.token_hex(32)
+
+ click.echo("\nAdd these to your .env file:\n")
+ click.echo(f"SECRET_KEY={secret_key}")
+ click.echo(f"JWT_SECRET_KEY={jwt_secret_key}")
+ click.echo()
+
+
+def init_db():
+ """Initialize the database."""
+ app = create_app()
+ with app.app_context():
+ db.create_all()
+ click.echo(click.style('Database initialized successfully!', fg='green'))
+
+
[email protected]_option(prompt='Are you sure you want to drop all tables?')
+def drop_db():
+ """Drop all database tables."""
+ app = create_app()
+ with app.app_context():
+ db.drop_all()
+ click.echo(click.style('All tables dropped!', fg='yellow'))
+
+
+if __name__ == '__main__':
+ cli()
diff --git a/backend/requirements.txt b/backend/requirements.txt
index 4c91700b..3f462a6c 100644
--- a/backend/requirements.txt
+++ b/backend/requirements.txt
@@ -34,3 +34,6 @@ PyYAML==6.0.1
# Rate limiting
Flask-Limiter==3.5.0
+
+# CLI
+click==8.1.7
diff --git a/deploy/serverkit.service b/deploy/serverkit.service
index 10956eb8..f233027b 100644
--- a/deploy/serverkit.service
+++ b/deploy/serverkit.service
@@ -1,6 +1,6 @@
[Unit]
Description=ServerKit Web Server Management Dashboard
-Documentation=https://github.com/yourusername/serverkit
+Documentation=https://github.com/jhd3197/serverkit
After=network.target docker.service
Requires=docker.service
diff --git a/docker-compose.yml b/docker-compose.yml
index a0080156..009aa252 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,4 +1,5 @@
-# Docker Compose - Development Configuration
+# ServerKit Docker Compose
+# Usage: docker compose up -d
version: '3.8'
services:
@@ -8,19 +9,26 @@ services:
dockerfile: Dockerfile
container_name: serverkit-backend
environment:
- - FLASK_ENV=development
- - DATABASE_URL=sqlite:///serverkit.db
- - SECRET_KEY=${SECRET_KEY:-dev-secret-key-change-in-production}
- - JWT_SECRET_KEY=${JWT_SECRET_KEY:-jwt-secret-key-change-in-production}
- - CORS_ORIGINS=http://localhost:5173,http://localhost:3000
+ - FLASK_ENV=${FLASK_ENV:-production}
+ - DATABASE_URL=${DATABASE_URL:-sqlite:///serverkit.db}
+ - SECRET_KEY=${SECRET_KEY:?SECRET_KEY is required}
+ - JWT_SECRET_KEY=${JWT_SECRET_KEY:?JWT_SECRET_KEY is required}
+ - CORS_ORIGINS=${CORS_ORIGINS:-http://localhost}
volumes:
- - ./backend:/app
- - backend-data:/app/instance
- ports:
- - "5000:5000"
+ - serverkit-data:/app/instance
+ - /var/log:/var/log:ro
+ - /home:/home:ro
+ - /opt:/opt:ro
+ - /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- serverkit-network
restart: unless-stopped
+ healthcheck:
+ test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5000/api/v1/health')"]
+ interval: 30s
+ timeout: 10s
+ retries: 3
+ start_period: 10s
frontend:
build:
@@ -28,16 +36,26 @@ services:
dockerfile: Dockerfile
container_name: serverkit-frontend
depends_on:
- - backend
+ backend:
+ condition: service_healthy
ports:
- - "80:80"
+ - "${PORT:-80}:80"
+ - "${SSL_PORT:-443}:443"
+ volumes:
+ - ./nginx/ssl:/etc/nginx/ssl:ro
networks:
- serverkit-network
restart: unless-stopped
+ healthcheck:
+ test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/"]
+ interval: 30s
+ timeout: 10s
+ retries: 3
networks:
serverkit-network:
driver: bridge
volumes:
- backend-data:
+ serverkit-data:
+ name: serverkit-data
diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md
index 7197c308..ca232ae3 100644
--- a/docs/DEPLOYMENT.md
+++ b/docs/DEPLOYMENT.md
@@ -1,73 +1,169 @@
# ServerKit Deployment Guide
-This guide covers deploying ServerKit in production using Docker.
+Complete guide for deploying ServerKit on Ubuntu servers.
+
+## Quick Install (Ubuntu)
+
+```bash
+# One-line install
+curl -fsSL https://raw.githubusercontent.com/jhd3197/serverkit/main/install.sh | bash
+
+# Or clone and install manually
+git clone https://github.com/jhd3197/serverkit.git
+cd serverkit
+chmod +x serverkit
+./serverkit install
+```
## Prerequisites
+- Ubuntu 20.04+ (or Debian 11+)
- Docker 20.10+ and Docker Compose 2.0+
-- A server with at least 1GB RAM
-- A domain name (for SSL/HTTPS)
-- SSL certificate (Let's Encrypt recommended)
+- At least 1GB RAM
+- Domain name (for SSL/HTTPS)
+
+## CLI Commands
+
+ServerKit includes a management CLI for common administrative tasks.
-## Quick Start (Development)
+### Service Management
```bash
-# Clone the repository
-git clone https://github.com/yourusername/serverkit.git
-cd serverkit
+# Start/Stop/Restart
+serverkit start
+serverkit stop
+serverkit restart
-# Start with Docker Compose
-docker compose up -d
+# View status
+serverkit status
-# Access at http://localhost
+# View logs
+serverkit logs # All services
+serverkit logs backend # Backend only
+serverkit logs frontend # Frontend only
+
+# Update to latest version
+serverkit update
+
+# Uninstall
+serverkit uninstall
```
-## Production Deployment
+### User Management
+
+```bash
+# Create admin user
+serverkit create-admin
+# Prompts for: email, username, password
+
+# Reset a user's password
+serverkit reset-password
+# Prompts for: email, new password
+
+# Unlock a locked account (after failed login attempts)
+serverkit unlock-user
+# Prompts for: email
+
+# List all users
+serverkit list-users
-### 1. Generate Secure Keys
+# Promote user to admin
+serverkit make-admin
+# Prompts for: email
+
+# Deactivate/Activate user
+serverkit deactivate-user
+serverkit activate-user
+```
+
+### Database Management
+
+```bash
+# Initialize database
+serverkit init-db
+
+# Backup database
+serverkit backup-db
+# Creates: backup/serverkit-YYYYMMDD-HHMMSS.db
+
+# Restore from backup
+serverkit restore-db backup/serverkit-20240115-120000.db
+```
+
+### Utility Commands
```bash
-# Generate SECRET_KEY
-python -c "import secrets; print(secrets.token_hex(32))"
+# Generate secure keys for .env
+serverkit generate-keys
+
+# Edit configuration
+serverkit config
-# Generate JWT_SECRET_KEY
-python -c "import secrets; print(secrets.token_hex(32))"
+# Open shell in backend container
+serverkit shell
+
+# Show help
+serverkit help
```
-### 2. Create Environment File
+## Manual Installation
-Create `.env` in the project root:
+### 1. Install Docker
```bash
-# Required - generate unique keys!
-SECRET_KEY=your-generated-secret-key
-JWT_SECRET_KEY=your-generated-jwt-secret-key
+# Install Docker
+curl -fsSL https://get.docker.com | sh
-# Database (SQLite by default, or use PostgreSQL)
-DATABASE_URL=sqlite:///serverkit.db
-# DATABASE_URL=postgresql://user:pass@host:5432/serverkit
+# Add user to docker group
+sudo usermod -aG docker $USER
-# CORS origins (your domain)
+# Log out and back in, then verify
+docker --version
+```
+
+### 2. Clone Repository
+
+```bash
+git clone https://github.com/jhd3197/serverkit.git /opt/serverkit
+cd /opt/serverkit
+```
+
+### 3. Configure Environment
+
+```bash
+# Generate secure keys
+serverkit generate-keys
+
+# Create .env file
+cat > .env << 'EOF'
+SECRET_KEY=<paste-generated-key>
+JWT_SECRET_KEY=<paste-generated-key>
+DATABASE_URL=sqlite:///serverkit.db
CORS_ORIGINS=https://yourdomain.com
+PORT=80
+SSL_PORT=443
+FLASK_ENV=production
+EOF
```
-### 3. SSL Certificate Setup
+### 4. SSL Certificate Setup
-#### Using Let's Encrypt (Recommended)
+#### Option A: Let's Encrypt (Recommended)
```bash
-# Create directories
-mkdir -p nginx/ssl
+# Install certbot
+sudo apt install certbot
-# Install certbot and get certificate
+# Get certificate (stop any service on port 80 first)
sudo certbot certonly --standalone -d yourdomain.com
# Copy certificates
sudo cp /etc/letsencrypt/live/yourdomain.com/fullchain.pem nginx/ssl/
sudo cp /etc/letsencrypt/live/yourdomain.com/privkey.pem nginx/ssl/
+sudo chown -R $USER:$USER nginx/ssl/
```
-#### Using Self-Signed (Testing Only)
+#### Option B: Self-Signed (Development Only)
```bash
mkdir -p nginx/ssl
@@ -77,37 +173,33 @@ openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-subj "/CN=localhost"
```
-### 4. Deploy
+### 5. Build and Start
```bash
-# Build and start production containers
-docker compose -f docker-compose.prod.yml up -d --build
+# Build containers
+docker compose build
-# Check status
-docker compose -f docker-compose.prod.yml ps
+# Start services
+docker compose up -d
-# View logs
-docker compose -f docker-compose.prod.yml logs -f
+# Verify
+serverkit status
```
-### 5. Initial Setup
+### 6. Create Admin User
-1. Navigate to `https://yourdomain.com`
-2. Register the first admin user
-3. Configure server monitoring settings
+```bash
+serverkit create-admin
+```
-## Systemd Service (Optional)
+## Systemd Service
-Install as a system service for automatic startup:
+Run ServerKit as a system service:
```bash
-# Copy the service file
+# Copy service file
sudo cp deploy/serverkit.service /etc/systemd/system/
-# Copy project to /opt
-sudo mkdir -p /opt/serverkit
-sudo cp -r . /opt/serverkit/
-
# Enable and start
sudo systemctl daemon-reload
sudo systemctl enable serverkit
@@ -117,55 +209,56 @@ sudo systemctl start serverkit
sudo systemctl status serverkit
```
-## Maintenance
+## Configuration Reference
-### Updating
+### Environment Variables
-```bash
-cd /opt/serverkit
-git pull
-docker compose -f docker-compose.prod.yml up -d --build
-```
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `SECRET_KEY` | Flask secret key | Required |
+| `JWT_SECRET_KEY` | JWT signing key | Required |
+| `DATABASE_URL` | Database connection string | `sqlite:///serverkit.db` |
+| `CORS_ORIGINS` | Allowed CORS origins | `http://localhost` |
+| `PORT` | HTTP port | `80` |
+| `SSL_PORT` | HTTPS port | `443` |
+| `FLASK_ENV` | Environment mode | `production` |
-### Backup Database
+### Docker Volumes
-```bash
-# SQLite
-docker compose -f docker-compose.prod.yml exec backend \
- cp /app/instance/serverkit.db /app/instance/serverkit.db.backup
+| Volume | Purpose |
+|--------|---------|
+| `serverkit-data` | Database and application data |
+| `nginx/ssl` | SSL certificates |
-# Copy to host
-docker cp serverkit-backend:/app/instance/serverkit.db.backup ./backup/
-```
+## Common Tasks
-### View Logs
+### Auto-renew SSL Certificate
```bash
-# All services
-docker compose -f docker-compose.prod.yml logs -f
+# Add to crontab
+sudo crontab -e
-# Specific service
-docker compose -f docker-compose.prod.yml logs -f backend
-docker compose -f docker-compose.prod.yml logs -f nginx
+# Add this line (renews at 2:30 AM daily)
+30 2 * * * certbot renew --quiet && cp /etc/letsencrypt/live/yourdomain.com/*.pem /opt/serverkit/nginx/ssl/ && docker compose -f /opt/serverkit/docker-compose.yml restart frontend
```
-### Restart Services
+### Change Domain
-```bash
-docker compose -f docker-compose.prod.yml restart
-# or
-sudo systemctl restart serverkit
-```
+1. Update `.env` file: `CORS_ORIGINS=https://newdomain.com`
+2. Get new SSL certificate
+3. Restart: `serverkit restart`
-## Security Checklist
+### Scale for Production
-- [ ] Generated unique SECRET_KEY and JWT_SECRET_KEY
-- [ ] SSL/TLS certificate configured
-- [ ] Firewall configured (ports 80, 443 only)
-- [ ] Regular backups configured
-- [ ] Monitoring/alerting set up
-- [ ] Rate limiting verified working
-- [ ] Security headers present (check with browser dev tools)
+For high-traffic deployments, consider:
+
+```bash
+# Use PostgreSQL instead of SQLite
+DATABASE_URL=postgresql://user:pass@localhost:5432/serverkit
+
+# Add Redis for session storage
+# Edit docker-compose.yml to add redis service
+```
## Troubleshooting
@@ -173,61 +266,68 @@ sudo systemctl restart serverkit
```bash
# Check logs
-docker compose -f docker-compose.prod.yml logs backend
+serverkit logs backend
-# Check if port is in use
-sudo lsof -i :5000
-sudo lsof -i :80
+# Rebuild
+docker compose build --no-cache
+docker compose up -d
```
-### 502 Bad Gateway
+### Permission denied errors
+
+```bash
+# Fix Docker socket permissions
+sudo chmod 666 /var/run/docker.sock
+
+# Or add user to docker group
+sudo usermod -aG docker $USER
+# Then log out and back in
+```
-Usually means the backend isn't running:
+### Port already in use
```bash
-docker compose -f docker-compose.prod.yml ps
-docker compose -f docker-compose.prod.yml restart backend
+# Find what's using port 80
+sudo lsof -i :80
+
+# Stop the service or change PORT in .env
```
-### WebSocket connection failed
+### Reset everything
-Ensure nginx is properly proxying WebSocket connections. Check the `/socket.io` location block in nginx.conf.
+```bash
+# Stop and remove all containers and volumes
+serverkit stop
+docker compose down -v
+
+# Rebuild from scratch
+docker compose build --no-cache
+serverkit start
+serverkit init-db
+serverkit create-admin
+```
-### SSL Certificate Issues
+### Locked out / Forgot password
```bash
-# Test certificate
-openssl s_client -connect yourdomain.com:443 -servername yourdomain.com
+# Reset password via CLI
+serverkit reset-password
+# Enter email and new password
-# Check certificate expiry
-openssl x509 -in nginx/ssl/fullchain.pem -noout -dates
+# Or unlock account if locked
+serverkit unlock-user
```
-## Architecture
+## Security Checklist
-```
- ┌─────────────┐
- │ Client │
- └──────┬──────┘
- │
- ┌──────▼──────┐
- │ Nginx │
- │ (SSL/TLS) │
- └──────┬──────┘
- │
- ┌───────────────┼───────────────┐
- │ │ │
- ┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐
- │ Frontend │ │ Backend │ │ Socket.IO │
- │ (React) │ │ (Flask) │ │ (WebSocket) │
- └─────────────┘ └──────┬──────┘ └─────────────┘
- │
- ┌──────▼──────┐
- │ SQLite/ │
- │ PostgreSQL │
- └─────────────┘
-```
+- [ ] Generated unique SECRET_KEY and JWT_SECRET_KEY
+- [ ] Using HTTPS with valid SSL certificate
+- [ ] Firewall configured (allow only ports 80, 443, 22)
+- [ ] Regular backups configured
+- [ ] Admin password is strong
+- [ ] Updated to latest version
## Support
-For issues and questions, please open an issue on GitHub.
+- GitHub Issues: https://github.com/jhd3197/serverkit/issues
+- Documentation: https://github.com/jhd3197/serverkit/wiki
diff --git a/install.sh b/install.sh
new file mode 100644
index 00000000..27dfd102
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,147 @@
+#!/bin/bash
+#
+# ServerKit Quick Install Script for Ubuntu
+# Usage: curl -fsSL https://raw.githubusercontent.com/jhd3197/serverkit/main/install.sh | bash
+#
+
+set -e
+
+# Colors
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+BLUE='\033[0;34m'
+NC='\033[0m'
+
+echo -e "${BLUE}"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo " ServerKit Installer"
+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+echo -e "${NC}"
+
+# Check if running as root
+if [ "$EUID" -eq 0 ]; then
+ echo -e "${YELLOW}Warning: Running as root is not recommended${NC}"
+fi
+
+# Check Ubuntu
+if [ -f /etc/os-release ]; then
+ . /etc/os-release
+ if [ "$ID" != "ubuntu" ] && [ "$ID" != "debian" ]; then
+ echo -e "${YELLOW}Warning: This script is designed for Ubuntu/Debian${NC}"
+ fi
+fi
+
+echo -e "${BLUE}→ Checking prerequisites...${NC}"
+
+# Install Docker if not present
+if ! command -v docker &> /dev/null; then
+ echo -e "${BLUE}→ Installing Docker...${NC}"
+ 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}"
+fi
+
+# Install Docker Compose plugin if not present
+if ! 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
+fi
+
+# Clone repository
+INSTALL_DIR="/opt/serverkit"
+echo -e "${BLUE}→ Installing ServerKit to $INSTALL_DIR...${NC}"
+
+if [ -d "$INSTALL_DIR" ]; then
+ echo -e "${YELLOW}! Directory exists, updating...${NC}"
+ cd "$INSTALL_DIR"
+ sudo git pull
+else
+ sudo git clone https://github.com/jhd3197/serverkit.git "$INSTALL_DIR"
+ cd "$INSTALL_DIR"
+fi
+
+# Set permissions
+sudo chown -R $USER:$USER "$INSTALL_DIR"
+
+# Make CLI executable
+chmod +x serverkit
+
+# Create symlink for global access
+sudo ln -sf "$INSTALL_DIR/serverkit" /usr/local/bin/serverkit
+
+# Generate configuration
+if [ ! -f ".env" ]; then
+ echo -e "${BLUE}→ Generating configuration...${NC}"
+ SECRET_KEY=$(openssl rand -hex 32)
+ JWT_SECRET_KEY=$(openssl rand -hex 32)
+
+ cat > .env << EOF
+# ServerKit Configuration
+SECRET_KEY=$SECRET_KEY
+JWT_SECRET_KEY=$JWT_SECRET_KEY
+DATABASE_URL=sqlite:///serverkit.db
+CORS_ORIGINS=http://localhost
+PORT=80
+SSL_PORT=443
+FLASK_ENV=production
+EOF
+fi
+
+# Create SSL directory
+mkdir -p nginx/ssl
+
+# Generate self-signed certificate
+if [ ! -f "nginx/ssl/fullchain.pem" ]; then
+ echo -e "${BLUE}→ Generating SSL certificate...${NC}"
+ 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
+fi
+
+# Build and start
+echo -e "${BLUE}→ Building containers (this may take a few minutes)...${NC}"
+docker compose build
+
+echo -e "${BLUE}→ Starting services...${NC}"
+docker compose up -d
+
+# Wait for services
+echo -e "${BLUE}→ Waiting for services...${NC}"
+sleep 15
+
+# Final check
+echo ""
+if curl -s http://localhost > /dev/null 2>&1; then
+ 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 "For all commands: serverkit help"
+ echo ""
+else
+ echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ echo -e "${RED} Installation may have issues${NC}"
+ echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ echo ""
+ echo "Check logs with: serverkit logs"
+ echo ""
+fi
diff --git a/serverkit b/serverkit
new file mode 100644
index 00000000..66c7073a
--- /dev/null
+++ b/serverkit
@@ -0,0 +1,473 @@
+#!/bin/bash
+#
+# ServerKit CLI - Management tool for ServerKit
+# Usage: ./serverkit <command> [options]
+#
+
+set -e
+
+# Colors
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+BLUE='\033[0;34m'
+NC='\033[0m' # No Color
+
+# Configuration
+INSTALL_DIR="${SERVERKIT_DIR:-/opt/serverkit}"
+CONTAINER_NAME="serverkit-backend"
+COMPOSE_FILE="docker-compose.yml"
+
+# Helper functions
+print_header() {
+ echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
+ echo -e "${BLUE} ServerKit CLI${NC}"
+ 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_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"
+ exit 1
+ fi
+}
+
+check_installed() {
+ if [ ! -f "$INSTALL_DIR/$COMPOSE_FILE" ]; then
+ print_error "ServerKit is not installed in $INSTALL_DIR"
+ print_info "Run: ./serverkit install"
+ exit 1
+ fi
+}
+
+run_cli() {
+ docker exec -it $CONTAINER_NAME python cli.py "$@"
+}
+
+# Commands
+cmd_help() {
+ print_header
+ echo ""
+ 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"
+ echo " status Show service status"
+ echo " logs [service] View logs (backend, frontend, or all)"
+ echo " update Update to latest version"
+ echo " uninstall Uninstall ServerKit"
+ echo ""
+ echo "User Management:"
+ echo " create-admin Create a new admin user"
+ echo " reset-password Reset a user's password"
+ echo " unlock-user Unlock a locked user account"
+ echo " list-users List all users"
+ echo " make-admin Promote user to admin"
+ echo " deactivate-user Deactivate a user account"
+ echo " activate-user Activate a user account"
+ echo ""
+ echo "Database Commands:"
+ echo " init-db Initialize the database"
+ echo " backup-db Backup the database"
+ echo " restore-db Restore database from backup"
+ 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 " 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"
+
+ # 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
+
+ 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
+ print_success "ServerKit started"
+}
+
+cmd_stop() {
+ check_installed
+ cd "$INSTALL_DIR"
+ print_info "Stopping ServerKit..."
+ docker compose down
+ print_success "ServerKit stopped"
+}
+
+cmd_restart() {
+ check_installed
+ cd "$INSTALL_DIR"
+ print_info "Restarting ServerKit..."
+ docker compose restart
+ print_success "ServerKit restarted"
+}
+
+cmd_status() {
+ check_installed
+ cd "$INSTALL_DIR"
+ print_header
+ echo ""
+ docker compose ps
+ echo ""
+
+ # 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
+}
+
+cmd_logs() {
+ check_installed
+ cd "$INSTALL_DIR"
+ service="${1:-}"
+ if [ -n "$service" ]; then
+ docker compose logs -f "$service"
+ else
+ docker compose logs -f
+ fi
+}
+
+cmd_update() {
+ check_installed
+ cd "$INSTALL_DIR"
+ print_info "Updating ServerKit..."
+
+ # Pull latest changes
+ if [ -d ".git" ]; then
+ git pull
+ fi
+
+ # Rebuild and restart
+ docker compose build
+ docker compose up -d
+
+ print_success "ServerKit updated"
+}
+
+cmd_uninstall() {
+ print_header
+ echo ""
+ print_warning "This will remove ServerKit and all data!"
+ read -p "Are you sure? (y/N) " -n 1 -r
+ echo
+
+ if [[ $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_success "ServerKit uninstalled"
+ fi
+}
+
+cmd_create_admin() {
+ check_installed
+ print_info "Creating admin user..."
+ run_cli create-admin
+}
+
+cmd_reset_password() {
+ check_installed
+ print_info "Resetting password..."
+ run_cli reset-password
+}
+
+cmd_unlock_user() {
+ check_installed
+ run_cli unlock-user
+}
+
+cmd_list_users() {
+ check_installed
+ run_cli list-users
+}
+
+cmd_make_admin() {
+ check_installed
+ run_cli make-admin
+}
+
+cmd_deactivate_user() {
+ check_installed
+ run_cli deactivate-user
+}
+
+cmd_activate_user() {
+ check_installed
+ run_cli activate-user
+}
+
+cmd_init_db() {
+ check_installed
+ run_cli 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"
+}
+
+cmd_restore_db() {
+ check_installed
+ cd "$INSTALL_DIR"
+
+ if [ -z "$1" ]; then
+ echo "Available backups:"
+ ls -la backup/*.db 2>/dev/null || echo "No backups found"
+ echo ""
+ read -p "Enter backup file path: " BACKUP_FILE
+ else
+ BACKUP_FILE="$1"
+ fi
+
+ if [ ! -f "$BACKUP_FILE" ]; then
+ print_error "Backup file not found: $BACKUP_FILE"
+ exit 1
+ fi
+
+ print_warning "This will overwrite the current database!"
+ read -p "Continue? (y/N) " -n 1 -r
+ echo
+
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
+ docker cp "$BACKUP_FILE" $CONTAINER_NAME:/app/instance/serverkit.db
+ docker compose restart backend
+ print_success "Database restored"
+ fi
+}
+
+cmd_generate_keys() {
+ check_docker
+ print_header
+ echo ""
+ 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)
+ 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"
+}
+
+# Main
+case "${1:-help}" in
+ help|--help|-h)
+ cmd_help
+ ;;
+ install)
+ cmd_install
+ ;;
+ start)
+ cmd_start
+ ;;
+ stop)
+ cmd_stop
+ ;;
+ restart)
+ cmd_restart
+ ;;
+ status)
+ cmd_status
+ ;;
+ logs)
+ cmd_logs "$2"
+ ;;
+ update)
+ cmd_update
+ ;;
+ uninstall)
+ cmd_uninstall
+ ;;
+ create-admin)
+ cmd_create_admin
+ ;;
+ reset-password)
+ cmd_reset_password
+ ;;
+ unlock-user)
+ cmd_unlock_user
+ ;;
+ list-users)
+ cmd_list_users
+ ;;
+ make-admin)
+ cmd_make_admin
+ ;;
+ deactivate-user)
+ cmd_deactivate_user
+ ;;
+ activate-user)
+ cmd_activate_user
+ ;;
+ init-db)
+ cmd_init_db
+ ;;
+ backup-db)
+ cmd_backup_db
+ ;;
+ restore-db)
+ cmd_restore_db "$2"
+ ;;
+ generate-keys)
+ cmd_generate_keys
+ ;;
+ shell)
+ cmd_shell
+ ;;
+ config)
+ cmd_config
+ ;;
+ *)
+ print_error "Unknown command: $1"
+ echo "Run 'serverkit help' for usage"
+ exit 1
+ ;;
+esac