Files
tilbudgivern/docs/deployment/PM2_GUIDE.md
alexpolo1 4a372d2e28 clean up
2025-10-30 18:28:58 +00:00

3.1 KiB

PM2 Management Guide for Tilbudgivern

Setup Complete!

All services are now running under PM2 with:

  • Auto-restart on crash
  • File watching for auto-reload (unified server only)
  • Environment variables from .env
  • No sudo required for database access
  • Proper logging

Quick Commands

Using the helper scripts:

# Start all services
bash start-with-pm2.sh

# Run complete build and test
bash build-and-test-complete.sh

Using PM2 directly:

# Set node path first
export NODE_PATH="/home/alex/.vscode-server/cli/servers/Stable-7d842fb85a0275a4a8e4d7e040d2625abbf7f084/server/node"

# List all processes
$NODE_PATH /usr/local/bin/pm2 list

# View logs (live)
$NODE_PATH /usr/local/bin/pm2 logs

# View logs for specific service
$NODE_PATH /usr/local/bin/pm2 logs tilbudgivern-unified

# Monitor CPU/Memory
$NODE_PATH /usr/local/bin/pm2 monit

# Restart a service
$NODE_PATH /usr/local/bin/pm2 restart tilbudgivern-unified

# Restart all services
$NODE_PATH /usr/local/bin/pm2 restart all

# Stop a service
$NODE_PATH /usr/local/bin/pm2 stop tilbudgivern-unified

# Delete/remove a service
$NODE_PATH /usr/local/bin/pm2 delete tilbudgivern-unified

# View detailed info
$NODE_PATH /usr/local/bin/pm2 show tilbudgivern-unified

Services Running

  1. tilbudgivern-unified (Port 4031)

    • Main application server
    • Auto-reloads on file changes
    • Serves React frontend
  2. analytics-api (Port 4032)

    • Analytics and reporting API
  3. carpenter-tasks-api (Port 4033)

    • Carpenter tasks management API

Application URLs

Recent Changes

  1. PM2 Management: All services now run under PM2
  2. No Sudo Required: Database credentials from .env file
  3. Two Markup Sliders:
    • Materials: 20% default (0-50% range)
    • Labor: 2% default (0-20% range, 0.5% steps)
  4. Wall Height Fixed: Now saves and loads correctly from database

Troubleshooting

If services don't start:

# Check PM2 status
$NODE_PATH /usr/local/bin/pm2 list

# View error logs
$NODE_PATH /usr/local/bin/pm2 logs --err

# Restart everything
bash start-with-pm2.sh

If changes don't appear:

  1. PM2 auto-reloads backend (watch mode enabled)
  2. Frontend needs manual browser refresh (Ctrl+Shift+R)

Database issues:

# Check .env file has correct credentials
cat .env | grep DB_

# Test database connection
mysql -u"${DB_USER}" -p"${DB_PASSWORD}" -h"${DB_HOST}" -e "SHOW DATABASES;"

File Locations

  • PM2 Config: /mnt/HC_Volume_103713257/tilbudgivern/ecosystem.config.json
  • PM2 Logs: /mnt/HC_Volume_103713257/tilbudgivern/logs/
  • Environment: /mnt/HC_Volume_103713257/tilbudgivern/.env
  • Frontend Build: /mnt/HC_Volume_103713257/tilbudgivern/frontend/build/

Auto-start on boot (optional)

To make PM2 start on system boot:

sudo env PATH=$PATH:/home/alex/.vscode-server/cli/servers/Stable-7d842fb85a0275a4a8e4d7e040d2625abbf7f084/server /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u alex --hp /home/alex