fix: swap creation + China npm mirror for 1GB VPS
- Creates 1GB swap file before build (prevents OOM on low-RAM VPS) - Auto-detects China network block on npmjs.org → switches to npmmirror - deploy/setup.sh: minimal script for pre-built tarball deployment
This commit is contained in:
+21
@@ -32,6 +32,20 @@ bail() { err "Unsupported OS: $OS. Install manually: $1"; exit 1; }
|
||||
|
||||
# ── Sudo check ─────────────────────────────────
|
||||
sudo -v || (err "sudo required" && exit 1)
|
||||
SU() { echo "$SUDO_PASS" | sudo -S "$@" 2>/dev/null || sudo "$@"; }
|
||||
|
||||
# ── Swap (prevent OOM on low-RAM VPS) ──────────
|
||||
if [ "$(free -m | awk '/^Swap:/{print $2}')" -lt 512 ]; then
|
||||
info "Creating 1GB swap file..."
|
||||
SU dd if=/dev/zero of=/swapfile bs=1M count=1024 status=none
|
||||
SU chmod 600 /swapfile
|
||||
SU mkswap /swapfile >/dev/null
|
||||
SU swapon /swapfile
|
||||
if ! grep -q /swapfile /etc/fstab 2>/dev/null; then
|
||||
echo '/swapfile none swap sw 0 0' | SU tee -a /etc/fstab >/dev/null
|
||||
fi
|
||||
log "Swap created (1GB)"
|
||||
fi
|
||||
|
||||
# ── git + curl ─────────────────────────────────
|
||||
for cmd in git curl; do
|
||||
@@ -84,6 +98,13 @@ else
|
||||
log "Node.js $(node -v) already installed"
|
||||
fi
|
||||
|
||||
# ── npm mirror (auto-detect China) ──────────────
|
||||
if curl -sI --connect-timeout 3 https://registry.npmjs.org/ 2>&1 | grep -q "timed out\|Connection refused\|Could not resolve\|Network"; then
|
||||
info "npmjs.org unreachable — switching to China mirror"
|
||||
npm config set registry https://registry.npmmirror.com
|
||||
log "Using npmmirror.com"
|
||||
fi
|
||||
|
||||
# ── Caddy ────────────────────────────────────────
|
||||
if ! command -v caddy &>/dev/null; then
|
||||
info "Installing Caddy..."
|
||||
|
||||
Reference in New Issue
Block a user