Raja
Raja

Reputation: 368

Why is 'npm install' and 'pm2 restart all' not executing?

Everything works fine for my MERN app in the workflow except for the start of npm install onwards. The workflow succeeds. I need to manually restart the server to see any backend changes. Any idea what's going on here? Nothing shown in the logs.

name: Deploy to DigitalOcean

on:
 push:
    branches:
      - main

jobs:
  deploy:
  runs-on: ubuntu-latest

steps:
  # Step 1: Check out the code from the repository
  - name: Checkout code
    uses: actions/checkout@v3

  # Step 2: Set up SSH agent using your private key stored in GitHub Secrets
  - name: Set up SSH agent
    uses: webfactory/[email protected]
    with:
      ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

  # Step 3: Deploy to DigitalOcean and create a .env file
  - name: Deploy to DigitalOcean
    run: |
      ssh -o StrictHostKeyChecking=no [email protected] << 'EOF'
        # Navigate to the application directory
        cd /root/circlo-app
        
        # Pull the latest code from the main branch
        git pull origin main
        
        # Create a .env file
        cat <<EOT > .env
        ...env vars
        EOT
        
        npm ci --production
        npm ci -g pm2
        echo "Restarting application..."
        pm2 restart all
        pm2 list
        echo "Application restarted."
      EOF
      echo "Deployment complete."

Upvotes: 0

Views: 17

Answers (1)

Alaindeseine
Alaindeseine

Reputation: 4493

You are doing this : npm ci -g pm2 . This will reinstall pm2 so if you reinstall, you loose jobs.

Thus, nothing will restart. You'll have to create pm2 task instead of restart.

Upvotes: 0

Related Questions