Use systemd restart in deploy.sh + avoid log permission issues
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
This commit is contained in:
51
deploy.sh
51
deploy.sh
@ -146,21 +146,28 @@ if ! $FRONTEND_ONLY; then
|
|||||||
python -c "from app.database import init_db; import asyncio; asyncio.run(init_db())"
|
python -c "from app.database import init_db; import asyncio; asyncio.run(init_db())"
|
||||||
echo " ✓ DB migrations applied"
|
echo " ✓ DB migrations applied"
|
||||||
|
|
||||||
# Restart backend process (production typically runs without --reload)
|
# Restart backend via systemd when available (preferred). Fallback to nohup only if the unit is missing.
|
||||||
|
if systemctl list-unit-files 2>/dev/null | grep -q '^pounce-backend\\.service'; then
|
||||||
|
echo " Restarting backend via systemd..."
|
||||||
|
echo "user" | sudo -S systemctl restart pounce-backend
|
||||||
|
sleep 2
|
||||||
|
if systemctl is-active --quiet pounce-backend; then
|
||||||
|
echo " ✓ Backend restarted (systemd)"
|
||||||
|
else
|
||||||
|
echo " ⚠ Backend restart failed (systemd). Check: journalctl -u pounce-backend -n 80"
|
||||||
|
fi
|
||||||
|
else
|
||||||
BACKEND_PID=$(pgrep -f 'uvicorn app.main:app' | awk 'NR==1{print; exit}')
|
BACKEND_PID=$(pgrep -f 'uvicorn app.main:app' | awk 'NR==1{print; exit}')
|
||||||
|
|
||||||
if [ -n "$BACKEND_PID" ]; then
|
if [ -n "$BACKEND_PID" ]; then
|
||||||
echo " Restarting backend (PID: $BACKEND_PID)..."
|
echo " Restarting backend (PID: $BACKEND_PID)..."
|
||||||
kill "$BACKEND_PID" 2>/dev/null || true
|
kill "$BACKEND_PID" 2>/dev/null || true
|
||||||
sleep 1
|
sleep 1
|
||||||
nohup uvicorn app.main:app --host 0.0.0.0 --port 8000 > backend.log 2>&1 &
|
|
||||||
sleep 2
|
|
||||||
echo " ✓ Backend restarted"
|
|
||||||
else
|
else
|
||||||
echo " ⚠ Backend not running, starting..."
|
echo " ⚠ Backend not running, starting..."
|
||||||
nohup uvicorn app.main:app --host 0.0.0.0 --port 8000 > backend.log 2>&1 &
|
fi
|
||||||
|
nohup uvicorn app.main:app --host 0.0.0.0 --port 8000 > /tmp/pounce-backend-nohup.log 2>&1 &
|
||||||
sleep 2
|
sleep 2
|
||||||
echo " ✓ Backend started"
|
echo " ✓ Backend started (nohup fallback)"
|
||||||
fi
|
fi
|
||||||
BACKEND_EOF
|
BACKEND_EOF
|
||||||
else
|
else
|
||||||
@ -205,37 +212,41 @@ if ! $BACKEND_ONLY; then
|
|||||||
cp -r public .next/standalone/public
|
cp -r public .next/standalone/public
|
||||||
echo " ✓ Public files copied to standalone"
|
echo " ✓ Public files copied to standalone"
|
||||||
|
|
||||||
# Gracefully restart Next.js
|
# Restart frontend via systemd when available (preferred). Fallback to nohup only if the unit is missing.
|
||||||
|
if systemctl list-unit-files 2>/dev/null | grep -q '^pounce-frontend\\.service'; then
|
||||||
|
echo " Restarting frontend via systemd..."
|
||||||
|
echo "user" | sudo -S systemctl restart pounce-frontend
|
||||||
|
sleep 2
|
||||||
|
if systemctl is-active --quiet pounce-frontend; then
|
||||||
|
echo " ✓ Frontend restarted (systemd)"
|
||||||
|
else
|
||||||
|
echo " ⚠ Frontend restart failed (systemd). Check: journalctl -u pounce-frontend -n 80"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Legacy nohup fallback
|
||||||
NEXT_PID=$(pgrep -af 'node \\.next/standalone/server\\.js|next start|next-server|next-serv' | awk 'NR==1{print $1; exit}')
|
NEXT_PID=$(pgrep -af 'node \\.next/standalone/server\\.js|next start|next-server|next-serv' | awk 'NR==1{print $1; exit}')
|
||||||
|
|
||||||
if [ -n "$NEXT_PID" ]; then
|
if [ -n "$NEXT_PID" ]; then
|
||||||
echo " Restarting Next.js (PID: $NEXT_PID)..."
|
echo " Restarting Next.js (PID: $NEXT_PID)..."
|
||||||
kill $NEXT_PID 2>/dev/null
|
kill $NEXT_PID 2>/dev/null
|
||||||
sleep 1
|
sleep 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure port is free (avoid EADDRINUSE)
|
|
||||||
lsof -ti:3000 2>/dev/null | xargs -r kill -9 2>/dev/null || true
|
lsof -ti:3000 2>/dev/null | xargs -r kill -9 2>/dev/null || true
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
# Start new instance with internal backend URL
|
|
||||||
if [ -f ".next/standalone/server.js" ]; then
|
if [ -f ".next/standalone/server.js" ]; then
|
||||||
echo " Starting Next.js (standalone)..."
|
echo " Starting Next.js (standalone)..."
|
||||||
nohup env NODE_ENV=production HOSTNAME=0.0.0.0 PORT=3000 BACKEND_URL=http://127.0.0.1:8000 node .next/standalone/server.js > frontend.log 2>&1 &
|
nohup env NODE_ENV=production HOSTNAME=0.0.0.0 PORT=3000 BACKEND_URL=http://127.0.0.1:8000 node .next/standalone/server.js > /tmp/pounce-frontend-nohup.log 2>&1 &
|
||||||
else
|
else
|
||||||
echo " Starting Next.js (npm start)..."
|
echo " Starting Next.js (npm start)..."
|
||||||
nohup env NODE_ENV=production BACKEND_URL=http://127.0.0.1:8000 npm run start > frontend.log 2>&1 &
|
nohup env NODE_ENV=production BACKEND_URL=http://127.0.0.1:8000 npm run start > /tmp/pounce-frontend-nohup.log 2>&1 &
|
||||||
fi
|
fi
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
# Verify
|
|
||||||
NEW_PID=$(pgrep -af 'node \\.next/standalone/server\\.js|next start|next-server|next-serv' | awk 'NR==1{print $1; exit}')
|
NEW_PID=$(pgrep -af 'node \\.next/standalone/server\\.js|next start|next-server|next-serv' | awk 'NR==1{print $1; exit}')
|
||||||
if [ -n "$NEW_PID" ]; then
|
if [ -n "$NEW_PID" ]; then
|
||||||
echo " ✓ Frontend running (PID: $NEW_PID)"
|
echo " ✓ Frontend running (nohup fallback, PID: $NEW_PID)"
|
||||||
else
|
else
|
||||||
echo " ⚠ Frontend may not have started correctly"
|
echo " ⚠ Frontend may not have started correctly"
|
||||||
echo " Last 80 lines of frontend.log:"
|
tail -n 80 /tmp/pounce-frontend-nohup.log || true
|
||||||
tail -n 80 frontend.log || true
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo " ✗ Build failed, keeping old version"
|
echo " ✗ Build failed, keeping old version"
|
||||||
|
|||||||
@ -12,8 +12,8 @@ Environment="PATH=/home/user/pounce/backend/venv/bin:/usr/local/bin:/usr/bin:/bi
|
|||||||
ExecStart=/home/user/pounce/backend/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000
|
ExecStart=/home/user/pounce/backend/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
StandardOutput=append:/home/user/pounce/backend/backend.log
|
StandardOutput=journal
|
||||||
StandardError=append:/home/user/pounce/backend/backend.log
|
StandardError=journal
|
||||||
|
|
||||||
# Hardening
|
# Hardening
|
||||||
NoNewPrivileges=true
|
NoNewPrivileges=true
|
||||||
|
|||||||
@ -15,8 +15,8 @@ Environment="BACKEND_URL=http://127.0.0.1:8000"
|
|||||||
ExecStart=/usr/bin/node /home/user/pounce/frontend/.next/standalone/server.js
|
ExecStart=/usr/bin/node /home/user/pounce/frontend/.next/standalone/server.js
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
StandardOutput=append:/home/user/pounce/frontend/frontend.log
|
StandardOutput=journal
|
||||||
StandardError=append:/home/user/pounce/frontend/frontend.log
|
StandardError=journal
|
||||||
|
|
||||||
# Hardening
|
# Hardening
|
||||||
NoNewPrivileges=true
|
NoNewPrivileges=true
|
||||||
|
|||||||
Reference in New Issue
Block a user