prod preparations

This commit is contained in:
2026-01-28 08:53:21 -05:00
parent 4850c16b87
commit b70d87c797
9 changed files with 1259 additions and 14 deletions

162
setup_production.sh Normal file
View File

@@ -0,0 +1,162 @@
#!/bin/bash
# Production Setup Script for Faction War Dispatch Bot
# Run this script on your Linux server
set -e # Exit on error
echo "========================================"
echo "Faction War Dispatch Bot - Setup Script"
echo "========================================"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (use sudo)"
exit 1
fi
# Get domain name
read -p "Enter your domain name (e.g., faction.yourdomain.com): " DOMAIN
if [ -z "$DOMAIN" ]; then
echo "Domain name is required!"
exit 1
fi
# Get email for Let's Encrypt
read -p "Enter your email for SSL certificate (Let's Encrypt): " EMAIL
if [ -z "$EMAIL" ]; then
echo "Email is required for SSL certificate!"
exit 1
fi
echo ""
echo "Installing required packages..."
apt update
apt install -y python3 python3-pip python3-venv nginx certbot python3-certbot-nginx git
echo ""
echo "Creating application user..."
if ! id "factionwar" &>/dev/null; then
adduser --system --group --home /opt/faction-war factionwar
fi
echo ""
echo "Setting up application directory..."
mkdir -p /opt/faction-war
cd /opt/faction-war
# If app directory doesn't exist, clone or expect user to upload files
if [ ! -d "app" ]; then
echo "Please upload your application files to /opt/faction-war/app"
echo "Or clone from git repository"
exit 1
fi
cd app
echo ""
echo "Setting up Python virtual environment..."
if [ ! -d "venv" ]; then
sudo -u factionwar python3 -m venv venv
fi
echo "Installing Python dependencies..."
sudo -u factionwar venv/bin/pip install -r requirements.txt
echo ""
echo "Creating data directory..."
mkdir -p /opt/faction-war/app/data
chown -R factionwar:factionwar /opt/faction-war/app/data
chmod 700 /opt/faction-war/app/data
echo ""
echo "Setting up environment file..."
if [ ! -f ".env" ]; then
cp .env.example .env
echo ""
echo "⚠️ IMPORTANT: Edit /opt/faction-war/app/.env with your configuration!"
echo " Generate secure secrets with:"
echo " - AUTH_PASSWORD: openssl rand -base64 32"
echo " - JWT_SECRET: openssl rand -hex 64"
echo ""
read -p "Press Enter to edit .env file now (or Ctrl+C to exit and edit later)..."
nano .env
fi
chown factionwar:factionwar .env
chmod 600 .env
echo ""
echo "Setting up Nginx configuration..."
cat nginx.conf.example | sed "s/yourdomain.com/$DOMAIN/g" > /tmp/faction-war-nginx.conf
cp /tmp/faction-war-nginx.conf /etc/nginx/sites-available/faction-war
ln -sf /etc/nginx/sites-available/faction-war /etc/nginx/sites-enabled/faction-war
# Remove default nginx site if it exists
rm -f /etc/nginx/sites-enabled/default
echo ""
echo "Testing Nginx configuration..."
nginx -t
echo ""
echo "Getting SSL certificate from Let's Encrypt..."
certbot --nginx -d $DOMAIN --non-interactive --agree-tos --email $EMAIL
echo ""
echo "Setting up systemd service..."
cp faction-war.service /etc/systemd/system/faction-war.service
systemctl daemon-reload
systemctl enable faction-war
systemctl start faction-war
echo ""
echo "Configuring firewall..."
ufw --force enable
ufw allow ssh
ufw allow 80/tcp
ufw allow 443/tcp
echo ""
echo "Setting up backup cron job..."
cat > /opt/faction-war/backup.sh << 'EOF'
#!/bin/bash
BACKUP_DIR="/opt/faction-war/backups"
DATE=$(date +%Y%m%d_%H%M%S)
APP_DIR="/opt/faction-war/app"
mkdir -p $BACKUP_DIR
tar -czf $BACKUP_DIR/data_backup_$DATE.tar.gz -C $APP_DIR data/
find $BACKUP_DIR -name "data_backup_*.tar.gz" -mtime +7 -delete
echo "Backup completed: data_backup_$DATE.tar.gz"
EOF
chmod +x /opt/faction-war/backup.sh
# Add to crontab if not already present
(crontab -l 2>/dev/null | grep -v backup.sh; echo "0 2 * * * /opt/faction-war/backup.sh") | crontab -
echo ""
echo "========================================"
echo "✅ Setup Complete!"
echo "========================================"
echo ""
echo "Your application should now be running at: https://$DOMAIN"
echo ""
echo "Important next steps:"
echo "1. Visit https://$DOMAIN and log in with your AUTH_PASSWORD"
echo "2. Configure your API keys in the Settings page"
echo "3. Test the application functionality"
echo ""
echo "Useful commands:"
echo " - Check status: sudo systemctl status faction-war"
echo " - View logs: sudo journalctl -u faction-war -f"
echo " - Restart: sudo systemctl restart faction-war"
echo " - Update code: cd /opt/faction-war/app && git pull && sudo systemctl restart faction-war"
echo ""
echo "Security reminders:"
echo " - Keep your .env file secure (chmod 600)"
echo " - Regularly update: apt update && apt upgrade"
echo " - Monitor logs for suspicious activity"
echo " - Backup data regularly (automated at 2 AM daily)"
echo ""