pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

PM2 reload <name> not being executed via github actions

Open Riwajchalise opened this issue 4 years ago • 8 comments

I am using github action to create a pipeline and using pm2 as the process manager.

pm2 reload server

When I run the above command locally the process is reloaded. When run it through action runner by running the bash command provided by github action that is - ./svc.sh

I get the following error: 0s Run pm2 restart server /actions-runner/_work/_temp/d8a0a9e1-465d-49aa-a242-6d80da54584f.sh: line 1: pm2: command not found Error: Process completed with exit code 127. However When I run it through ./run.sh the sequence of action including run pm2 reload server executes successfully.

Node: 12.X Pm2: 4.5.4

Riwajchalise avatar Feb 12 '21 09:02 Riwajchalise

i got exact same error! i have not found a solution.

cheseren avatar Apr 24 '21 06:04 cheseren

Hi what is your solution?

On Sat, Apr 24, 2021, 12:17 PM cheseren @.***> wrote:

i got exact same error! i have not found a solution.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Unitech/pm2/issues/4989#issuecomment-826043864, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFUYD6OLQMEBY362GJ7TTTLTKJQYBANCNFSM4XQMR56Q .

Riwajchalise avatar Apr 24 '21 06:04 Riwajchalise

To anyone who facing the same issue, the problem was is that yarn global bin path wasn't added in actions-runner .path file, so it simply wasn't able to run it.

Added :/home/ubuntu/.yarn/bin to the end of default path and restarted svc.sh solved the issue.

awHamer avatar Apr 30 '21 21:04 awHamer

Had the same issue, running the svc.sh with sudo fixed it. Resinstall the service with sudo ./svc.sh install and start it.

radioactive0238 avatar May 25 '21 11:05 radioactive0238

Had the same issue, running the svc.sh with sudo fixed it. Resinstall the service with sudo ./svc.sh install and start it.

It worked for me! Thanks.

mkilincaslan avatar Jul 07 '21 12:07 mkilincaslan

maybe duplicate https://github.com/Unitech/pm2/issues/1112

in my case in github actions $PATH env did not match server side (there was no path to npm folder)

the following helped me: connected to the server and entered npm config get prefix

got the following path: /home/ubuntu/.nvm/versions/node/v12.17.0

Then I just wrote the following code at the beginning of the ssh connection script (I use appleboy/ssh-action):

export PATH=$PATH:/home/ubuntu/.nvm/versions/node/v12.17.0/bin (also remember to add /bin)

image

after these actions, pm2 worked for me

can also help: https://stackoverflow.com/a/41317809/15601487 https://stackoverflow.com/a/65477541/15601487

JoCat avatar Dec 06 '21 14:12 JoCat

@JoCat this helped get pm2 running on my server. The output from npm config get prefix was completely different, but I used that and followed your way. Everything's working now. Thx.

mpagels avatar Feb 12 '22 20:02 mpagels

Had the same issue, running the svc.sh with sudo fixed it. Resinstall the service with sudo ./svc.sh install and start it.

Worked For me Thank you saved my day

bikmazer avatar Apr 26 '22 13:04 bikmazer

In ~/.bashrc comment line with return, and now all ssh will be interactively

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      #*) return;;
esac

And another solution

name: Deploy latest version

on:
  push:
    branches:
      - production

  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  deploy:
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Create SSH key
        run: |
          mkdir -p ~/.ssh/
          echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
          sudo chmod 600 ~/.ssh/id_ed25519
          echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts2
        shell: bash
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY_PROD }}
          SSH_KNOWN_HOSTS: ${{ vars.KNOWN_HOSTS }}

#      - name: Test SSH key
#        run: ssh -vT ${{ vars.EC2_USERNAME }}@${{ vars.EC2_HOST }} -p ${{ vars.EC2_HOST_PORT }}

      # Runs a single command using the runners shell
      - name: Make git pull
        run: |
          ssh ${{ vars.EC2_USERNAME }}@${{ vars.EC2_HOST }} -p ${{ vars.EC2_HOST_PORT }} '
            cd ./${{ github.event.repository.name }};
            git pull
          '

      - name: pm2 restart
        run: |
          ssh ${{ vars.EC2_USERNAME }}@${{ vars.EC2_HOST }} -p ${{ vars.EC2_HOST_PORT }} '
            export PATH=$PATH:/home/ubuntu/.nvm/versions/node/v18.13.0/bin;
            pm2 restart ${{ github.event.repository.name }} --update-env
          '

1xtr avatar Jan 28 '23 01:01 1xtr

In ~/.bashrc comment line with return, and now all ssh will be interactively

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      #*) return;;
esac

And another solution

name: Deploy latest version

on:
  push:
    branches:
      - production

  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  deploy:
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Create SSH key
        run: |
          mkdir -p ~/.ssh/
          echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
          sudo chmod 600 ~/.ssh/id_ed25519
          echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts2
        shell: bash
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY_PROD }}
          SSH_KNOWN_HOSTS: ${{ vars.KNOWN_HOSTS }}

#      - name: Test SSH key
#        run: ssh -vT ${{ vars.EC2_USERNAME }}@${{ vars.EC2_HOST }} -p ${{ vars.EC2_HOST_PORT }}

      # Runs a single command using the runners shell
      - name: Make git pull
        run: |
          ssh ${{ vars.EC2_USERNAME }}@${{ vars.EC2_HOST }} -p ${{ vars.EC2_HOST_PORT }} '
            cd ./${{ github.event.repository.name }};
            git pull
          '

      - name: pm2 restart
        run: |
          ssh ${{ vars.EC2_USERNAME }}@${{ vars.EC2_HOST }} -p ${{ vars.EC2_HOST_PORT }} '
            export PATH=$PATH:/home/ubuntu/.nvm/versions/node/v18.13.0/bin;
            pm2 restart ${{ github.event.repository.name }} --update-env
          '

This is working , thanks

vinaypugal-gox avatar Sep 04 '23 15:09 vinaypugal-gox