fixes deployment scripts
This commit is contained in:
@@ -173,13 +173,15 @@ info "Cloning from ${REPO_URL//:*@/:***@}…"
|
||||
|
||||
if [[ -d "${APP_DIR}/.git" ]]; then
|
||||
warn "App directory already contains a git repo — pulling latest instead."
|
||||
sudo -u "$APP_USER" git -C "$APP_DIR" pull
|
||||
git -C "$APP_DIR" pull
|
||||
else
|
||||
sudo -u "$APP_USER" git clone "$REPO_URL" "$APP_DIR" 2>&1 | \
|
||||
git clone "$REPO_URL" "$APP_DIR" 2>&1 | \
|
||||
sed 's/'"${GITEA_PASS:-NOPASS}"'/***REDACTED***/g' || \
|
||||
error "Git clone failed. Check your repo URL and credentials."
|
||||
fi
|
||||
|
||||
chown -R "${APP_USER}:${APP_USER}" "$APP_DIR"
|
||||
|
||||
success "Repository cloned to ${APP_DIR}"
|
||||
|
||||
# ── Step 4: Environment file ──────────────────────────────────────────────────
|
||||
@@ -201,10 +203,13 @@ success ".env written to ${ENV_FILE}"
|
||||
header "Step 5 / 9 — Install & Build"
|
||||
|
||||
info "Installing npm dependencies (this may take a minute)…"
|
||||
sudo -u "$APP_USER" npm --prefix "$APP_DIR" install --quiet
|
||||
npm --prefix "$APP_DIR" install --quiet
|
||||
|
||||
info "Building SvelteKit app…"
|
||||
sudo -u "$APP_USER" npm --prefix "$APP_DIR" run build
|
||||
npm --prefix "$APP_DIR" run build
|
||||
|
||||
# Fix ownership after build
|
||||
chown -R "${APP_USER}:${APP_USER}" "$APP_DIR"
|
||||
|
||||
success "Build complete"
|
||||
|
||||
@@ -218,7 +223,6 @@ module.exports = {
|
||||
name: 'etc-prs',
|
||||
script: '${APP_DIR}/build/index.js',
|
||||
cwd: '${APP_DIR}',
|
||||
user: '${APP_USER}',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: '3000',
|
||||
@@ -236,15 +240,11 @@ EOF
|
||||
chown "${APP_USER}:${APP_USER}" "$ECOSYSTEM"
|
||||
|
||||
info "Starting app with PM2…"
|
||||
sudo -u "$APP_USER" pm2 start "$ECOSYSTEM"
|
||||
sudo -u "$APP_USER" pm2 save
|
||||
pm2 start "$ECOSYSTEM"
|
||||
pm2 save
|
||||
|
||||
info "Configuring PM2 to start on boot…"
|
||||
# Capture the startup command PM2 emits and run it
|
||||
PM2_STARTUP=$(sudo -u "$APP_USER" pm2 startup systemd -u "$APP_USER" --hp /opt/etc-prs 2>&1 | grep "sudo env")
|
||||
if [[ -n "$PM2_STARTUP" ]]; then
|
||||
eval "$PM2_STARTUP"
|
||||
fi
|
||||
pm2 startup systemd -u root --hp /root | grep -E "^sudo" | bash || true
|
||||
|
||||
success "PM2 configured — app is running on 127.0.0.1:3000"
|
||||
|
||||
@@ -351,7 +351,7 @@ success "Firewall enabled (SSH + HTTP + HTTPS)"
|
||||
# Admin account
|
||||
info "Creating admin account '${ADMIN_USER}'…"
|
||||
cd "$APP_DIR"
|
||||
sudo -u "$APP_USER" node scripts/create-admin.js "$ADMIN_USER" "$ADMIN_PASS" || \
|
||||
node scripts/create-admin.js "$ADMIN_USER" "$ADMIN_PASS" || \
|
||||
warn "Admin creation failed — run manually: cd ${APP_DIR} && node scripts/create-admin.js <user> <pass>"
|
||||
success "Admin account '${ADMIN_USER}' created"
|
||||
|
||||
@@ -363,15 +363,15 @@ divider
|
||||
echo ""
|
||||
echo -e " ${BOLD}Site:${RESET} https://${DOMAIN}"
|
||||
echo -e " ${BOLD}Admin panel:${RESET} https://${DOMAIN}/admin"
|
||||
echo -e " ${BOLD}App logs:${RESET} sudo -u ${APP_USER} pm2 logs etc-prs"
|
||||
echo -e " ${BOLD}App logs:${RESET} pm2 logs etc-prs"
|
||||
echo -e " ${BOLD}DB path:${RESET} ${DATA_DIR}/personalities.db"
|
||||
echo -e " ${BOLD}Backups:${RESET} ${BACKUP_DIR}"
|
||||
echo ""
|
||||
echo -e " ${BOLD}Redeploy after a push:${RESET}"
|
||||
echo -e " ${CYAN} cd ${APP_DIR} && sudo -u ${APP_USER} git pull && \\"
|
||||
echo -e " sudo -u ${APP_USER} npm install && \\"
|
||||
echo -e " sudo -u ${APP_USER} npm run build && \\"
|
||||
echo -e " sudo -u ${APP_USER} pm2 reload etc-prs${RESET}"
|
||||
echo -e " ${CYAN} cd ${APP_DIR} && git pull && \\"
|
||||
echo -e " npm install && npm run build && \\"
|
||||
echo -e " chown -R ${APP_USER}:${APP_USER} ${APP_DIR} && \\"
|
||||
echo -e " pm2 reload etc-prs${RESET}"
|
||||
echo ""
|
||||
divider
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user