Skip to content

Commit 9903115

Browse files
edwhclaude
andcommitted
Add 4GB swap file on root filesystem to prevent OOM kills
Homepage request causes PHP-FPM to spike to ~400MB, exhausting all available memory (985MB total, ~400MB free at idle). Without swap, the OOM killer terminates PHP-FPM workers causing 502 errors. Swap on root (7.4GB free) not persistent volume — recreated each boot. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8b26e22 commit 9903115

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

.fly/scripts/startup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ mkdir -p /var/www/storage/logs
99
mkdir -p /var/www/bootstrap/cache
1010
chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache
1111

12+
# Create swap file on root filesystem (ephemeral, recreated each boot)
13+
SWAPFILE=/swapfile
14+
if [ ! -f "$SWAPFILE" ]; then
15+
echo "Creating 4GB swap file..."
16+
dd if=/dev/zero of="$SWAPFILE" bs=1M count=4096 2>/dev/null
17+
chmod 600 "$SWAPFILE"
18+
mkswap "$SWAPFILE"
19+
fi
20+
swapon "$SWAPFILE" 2>/dev/null || true
21+
1222
# Ensure log directories exist on the persistent volume (/var/log is mounted)
1323
mkdir -p /var/log/nginx
1424
mkdir -p /var/log/sysstat

0 commit comments

Comments
 (0)