Search code examples
node.jsamazon-ec2github-actionscicdpm2

Pm2 Process or Namespace BackendAPI not found github actions?


Hi I am just learning and implementing the github action for nodejs project on AWS server. I have executed all the commands. The node app is running and is accessible through the client side.

I have added the Github actions with runner and that is okay without pm2 restart command. Now I have started the server from AWS EC2 and running fine with pm2. But while adding the command of,

pm2 restart name-space

on github workspace file it fails, I am getting

[PM2] Spawning PM2 daemon with pm2_home=/home/ubuntu/.pm2
[PM2] PM2 Successfully daemonized
Use --update-env to update environment variables
Error: RROR] Process or Namespace BackendAPI not found
Error: Process completed with exit code 1.

My files are

workspace:

            # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
        # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

        name: Node.js CI/CD

        on:
        push:
            branches: [ "main" ]

        jobs:
        build:
            runs-on: self-hosted
            strategy:
            matrix:
                node-version: [18.x]
                # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
            steps:
            - uses: actions/checkout@v3
            - name: Use Node.js ${{ matrix.node-version }}
            uses: actions/setup-node@v3
            with:
                node-version: ${{ matrix.node-version }}
                cache: 'npm'
            - run: npm ci
            - run: |
                touch .env
                echo "${{ secrets.PROD_ENV_FILE }}" > .env
            - run: pm2 restart BackendAPI

what is the issue? anyone know?


Solution

  • Actually there was a minor issue, I needed to run the pm2 command with sudo.

    like this

    sudo pm2 restart server-name