Files
sibedas/server-setup.sh
2025-06-13 19:53:23 +07:00

61 lines
1.5 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Server setup untuk optimasi memory dan build
# Jalankan dengan sudo di server production
echo "🔧 Setting up server for optimized building..."
# 1. Check current memory
echo "📊 Current memory status:"
free -h
# 2. Setup swap file (temporary solution for low memory)
echo "💾 Setting up swap file (1GB)..."
if [ ! -f /swapfile ]; then
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
sysctl vm.swappiness=10
echo '/swapfile none swap sw 0 0' >> /etc/fstab
echo 'vm.swappiness=10' >> /etc/sysctl.conf
swapon /swapfile
echo "✅ Swap file created and activated"
else
echo " Swap file already exists"
fi
# 3. Optimize Node.js for production
echo "⚙️ Optimizing Node.js..."
npm config set fund false
npm config set audit false
# 4. Install PM2 untuk process management
echo "📦 Installing PM2..."
npm install -g pm2
# 5. Create PM2 ecosystem file for build process
cat > ecosystem.config.js << 'EOF'
module.exports = {
apps: [{
name: 'build-app',
script: 'npm',
args: 'run build:prod',
instances: 1,
autorestart: false,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
NODE_OPTIONS: '--max-old-space-size=1024'
}
}]
}
EOF
echo "✅ Server setup completed!"
echo ""
echo "📝 Now you can:"
echo " 1. Build with memory limit: npm run build:prod"
echo " 2. Build with PM2: pm2 start ecosystem.config.js"
echo " 3. Monitor: pm2 monit"
echo " 4. Check memory: free -h"