Files
moyosapp_beta.0.0.3.3_beta/scripts/setup-proxmox-container.sh
2026-01-16 19:04:48 +02:00

149 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# Setup script for Proxmox LXC container
# This script helps set up a new Proxmox LXC container for the Moyos Wedding App
# Usage: Run this script inside the LXC container after creation
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
# Check if running as root
if [ "$EUID" -ne 0 ]; then
error "This script must be run as root"
exit 1
fi
log "Starting Proxmox LXC container setup for Moyos Wedding App..."
# Update system
log "Updating system packages..."
apt-get update
apt-get upgrade -y
# Install base utilities
log "Installing base utilities..."
apt-get install -y \
curl \
wget \
git \
build-essential \
ca-certificates \
gnupg \
lsb-release \
vim \
htop \
net-tools
# Install Node.js 20.x
log "Installing Node.js 20.x..."
if ! command -v node &> /dev/null; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
NODE_VERSION=$(node --version)
log "Node.js installed: $NODE_VERSION"
else
NODE_VERSION=$(node --version)
warn "Node.js already installed: $NODE_VERSION"
fi
# Install PM2
log "Installing PM2..."
if ! command -v pm2 &> /dev/null; then
npm install -g pm2
pm2 startup systemd -u root --hp /root
log "PM2 installed and startup configured"
else
warn "PM2 already installed"
fi
# Create application directory
APP_DIR="/opt/moyos-wedding-app"
log "Creating application directory: $APP_DIR"
mkdir -p "$APP_DIR"
chown -R $SUDO_USER:$SUDO_USER "$APP_DIR" 2>/dev/null || true
# Create backup directory
BACKUP_DIR="/opt/backups"
log "Creating backup directory: $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"/{db,storage,config}
chmod 755 "$BACKUP_DIR"
# Create logs directory
LOG_DIR="/opt/moyos-wedding-app/app/logs"
log "Creating logs directory: $LOG_DIR"
mkdir -p "$LOG_DIR"
chmod 755 "$LOG_DIR"
# Install PostgreSQL client (if needed for database operations)
log "Installing PostgreSQL client..."
apt-get install -y postgresql-client
# Install Redis tools (if needed)
log "Installing Redis tools..."
apt-get install -y redis-tools
# Configure firewall (if ufw is installed)
if command -v ufw &> /dev/null; then
log "Configuring firewall..."
ufw allow 22/tcp # SSH
ufw allow 3000/tcp # Next.js app
warn "Firewall configured. Review rules with: ufw status"
fi
# Set up log rotation
log "Configuring log rotation..."
cat > /etc/logrotate.d/moyos-app <<EOF
$LOG_DIR/*.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 0640 root root
sharedscripts
}
EOF
log "Log rotation configured"
# Summary
echo ""
log "Container setup completed successfully!"
echo ""
info "Next steps:"
info "1. Clone repository: git clone <repo-url> $APP_DIR"
info "2. Navigate to app: cd $APP_DIR/app"
info "3. Configure environment: cp .env.local.example .env.production"
info "4. Edit .env.production with your values"
info "5. Run deployment: ./scripts/deploy.sh --production"
echo ""
info "Useful commands:"
info " - Check PM2 status: pm2 status"
info " - View logs: pm2 logs moyos-wedding-app"
info " - Monitor: pm2 monit"
info " - Health check: ./scripts/health-check.sh"
echo ""