108 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			108 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/bash
 | 
						||
 | 
						||
# Minimal startup script for Turmli Calendar on Raspberry Pi Zero
 | 
						||
# Uses minimal resources and avoids problematic dependencies
 | 
						||
 | 
						||
set -e
 | 
						||
 | 
						||
# Configuration
 | 
						||
APP_DIR="/opt/turmli-calendar"
 | 
						||
APP_USER="pi"
 | 
						||
APP_PORT="8000"
 | 
						||
VENV_PATH="$APP_DIR/venv"
 | 
						||
 | 
						||
# Colors for output
 | 
						||
RED='\033[0;31m'
 | 
						||
GREEN='\033[0;32m'
 | 
						||
YELLOW='\033[1;33m'
 | 
						||
BLUE='\033[0;34m'
 | 
						||
NC='\033[0m'
 | 
						||
 | 
						||
print_info() {
 | 
						||
    echo -e "${BLUE}ℹ${NC} $1"
 | 
						||
}
 | 
						||
 | 
						||
print_success() {
 | 
						||
    echo -e "${GREEN}✓${NC} $1"
 | 
						||
}
 | 
						||
 | 
						||
print_error() {
 | 
						||
    echo -e "${RED}✗${NC} $1"
 | 
						||
}
 | 
						||
 | 
						||
print_warning() {
 | 
						||
    echo -e "${YELLOW}⚠${NC} $1"
 | 
						||
}
 | 
						||
 | 
						||
# Check if running as correct user
 | 
						||
if [ "$EUID" -eq 0 ]; then 
 | 
						||
    print_error "Don't run this script as root. Use: ./start_minimal.sh"
 | 
						||
    exit 1
 | 
						||
fi
 | 
						||
 | 
						||
# Check if application directory exists
 | 
						||
if [ ! -d "$APP_DIR" ]; then
 | 
						||
    print_error "Application directory not found: $APP_DIR"
 | 
						||
    print_info "Please run the deployment script first: sudo ./deploy_rpi.sh install"
 | 
						||
    exit 1
 | 
						||
fi
 | 
						||
 | 
						||
# Check if virtual environment exists
 | 
						||
if [ ! -d "$VENV_PATH" ]; then
 | 
						||
    print_error "Virtual environment not found: $VENV_PATH"
 | 
						||
    print_info "Please run the deployment script first: sudo ./deploy_rpi.sh install"
 | 
						||
    exit 1
 | 
						||
fi
 | 
						||
 | 
						||
# Change to application directory
 | 
						||
cd "$APP_DIR"
 | 
						||
 | 
						||
# Show system resources before starting
 | 
						||
print_info "System resources before startup:"
 | 
						||
echo "  Memory: $(free -m | grep Mem | awk '{printf "Used: %dMB / Total: %dMB (%.1f%%)", $3, $2, $3*100/$2}')"
 | 
						||
echo "  Swap: $(free -m | grep Swap | awk '{printf "Used: %dMB / Total: %dMB", $3, $2}')"
 | 
						||
echo "  CPU Load: $(uptime | awk -F'load average:' '{print $2}')"
 | 
						||
echo "  Disk: $(df -h / | tail -1 | awk '{printf "Used: %s / Total: %s (%s)", $3, $2, $5}')"
 | 
						||
echo
 | 
						||
 | 
						||
# Set environment variables for minimal resource usage
 | 
						||
export PYTHONUNBUFFERED=1
 | 
						||
export PYTHONDONTWRITEBYTECODE=1
 | 
						||
export MALLOC_ARENA_MAX=2  # Limit memory fragmentation
 | 
						||
export MALLOC_MMAP_THRESHOLD_=131072
 | 
						||
export MALLOC_TRIM_THRESHOLD_=131072
 | 
						||
export MALLOC_MMAP_MAX_=65536
 | 
						||
 | 
						||
# Set a custom temp directory to avoid filling /tmp
 | 
						||
export TMPDIR="$APP_DIR/tmp"
 | 
						||
mkdir -p "$TMPDIR"
 | 
						||
 | 
						||
# Clear Python cache to free memory
 | 
						||
find "$APP_DIR" -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
 | 
						||
find "$APP_DIR" -name "*.pyc" -delete 2>/dev/null || true
 | 
						||
 | 
						||
print_info "Starting Turmli Calendar with minimal resources..."
 | 
						||
print_info "Access the application at: http://$(hostname -I | cut -d' ' -f1):${APP_PORT}"
 | 
						||
print_info "Press Ctrl+C to stop"
 | 
						||
echo
 | 
						||
 | 
						||
# Start uvicorn with minimal configuration
 | 
						||
# --workers 1: Single worker process
 | 
						||
# --loop asyncio: Standard event loop (no uvloop)
 | 
						||
# --no-access-log: Disable access logging to save resources
 | 
						||
# --log-level warning: Only log warnings and errors
 | 
						||
# --limit-concurrency 10: Limit concurrent connections
 | 
						||
# --timeout-keep-alive 5: Short keepalive timeout
 | 
						||
# --backlog 32: Smaller connection backlog
 | 
						||
 | 
						||
exec "$VENV_PATH/bin/python" -m uvicorn main:app \
 | 
						||
    --host 0.0.0.0 \
 | 
						||
    --port ${APP_PORT} \
 | 
						||
    --workers 1 \
 | 
						||
    --loop asyncio \
 | 
						||
    --no-access-log \
 | 
						||
    --log-level warning \
 | 
						||
    --limit-concurrency 10 \
 | 
						||
    --timeout-keep-alive 5 \
 | 
						||
    --backlog 32 \
 | 
						||
    --no-use-colors |