OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PM2 starts correctly in GitHub Actions workflow but not in SSH session – how to ensure consistent PM2 context?

  • Thread starter Thread starter Awais Kaleem
  • Start date Start date
A

Awais Kaleem

Guest
on github actions this file is executing successfully by starting pm2 instance as service but when in login to my ssh server and run command "pm2 ls" it does not list any pm2 instance as service.

here is my github actions workflow yml file:

Code:
name: Deploy Backend Test Environment
on:
  push:
    branches: 
      - backend-dev
jobs:
  deploy:
    runs-on: self-hosted
    defaults:
      run:
        # shell: bash -l {0}
        working-directory: backend
    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: 16
    
    - name: Install PM2 globally
      run: npm install -g pm2

    - name: Install dependencies
      run: npm install --legacy-peer-deps
      
    - name: starting backend
      run: npm run pm2dev

here are my package.json scripts which are being used in above workflow file:

Code:
"scripts": {
    "start": "env-cmd -f .env.prod nodemon --experimental-specifier-resolution=node server.js",
    "dev": "env-cmd -f .env.dev nodemon --experimental-specifier-resolution=node server.js",
    "list": "pm2 ls",
    "pm2": "pm2 delete 3fi-backend || true && PORT=3001 env-cmd -f .env.prod pm2 start server.js --name 3fi-backend",
    "pm2dev": "pm2 delete 3fi-backend-dev || true && PORT=3002 env-cmd -f .env.dev pm2 start server.js --name 3fi-backend-dev"
  },
on github actions this file is executing successfully by starting pm2 instance as service but when in login to my ssh server and run command "pm2 ls" it does not list any pm2 instance as service.

so i updated these in workflow file:

Code:
- name: Start backend
      run: |
        export PM2_HOME=$(pwd)/.pm2
        npm run pm2dev
        pm2 save --force

here are pm2 logs on github actions cli after adding export PM2_HOME=$(pwd)/.pm2

Code:
Run export PM2_HOME=$(pwd)/.pm2
  
Lifecycle scripts included in [email protected]:
  start
    env-cmd -f .env.prod nodemon --experimental-specifier-resolution=node server.js
available via npm run-script:
  dev
    env-cmd -f .env.dev nodemon --experimental-specifier-resolution=node server.js
  list
    pm2 ls
  pm2
    pm2 delete 3fi-backend || true && PORT=3001 env-cmd -f .env.prod pm2 start server.js --name 3fi-backend
  pm2dev
    pm2 delete 3fi-backend-dev || true && PORT=3002 env-cmd -f .env.dev pm2 start server.js --name 3fi-backend-dev
                        -------------
__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
 _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
  _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
   _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
    _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
     _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
      _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
       _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
        _\///______________\///______________\///__\///////////////__
                          Runtime Edition
        PM2 is a Production Process Manager for Node.js applications
                     with a built-in Load Balancer.
                Start and Daemonize any application:
                $ pm2 start app.js
                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4
                Monitor in production:
                $ pm2 monitor
                Make pm2 auto-boot at server restart:
                $ pm2 startup
                To go further checkout:
                http://pm2.io/
                        -------------
[PM2] Spawning PM2 daemon with pm2_home=/home/ubuntu/actions-runner/_work/landing_page_v2/landing_page_v2/backend/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Saving current process list...
[PM2] Successfully saved in /home/ubuntu/actions-runner/_work/landing_page_v2/landing_page_v2/backend/.pm2/dump.pm2

it seems on github actions context of pm2 home is

Code:
/home/ubuntu/actions-runner/_work/landing_page_v2/landing_page_v2/backend/.pm2/dump.pm2

but when in run "pm2 resurrect" on ssh server i get following logs:

Code:
[PM2] Resurrecting
[PM2] Restoring processes located in /home/ubuntu/.pm2/dump.pm2
[PM2][ERROR] Failed to read dump file in /home/ubuntu/.pm2/dump.pm2
[PM2] Restoring processes located in /home/ubuntu/.pm2/dump.pm2.bak
[PM2][ERROR] Failed to read dump file in /home/ubuntu/.pm2/dump.pm2.bak
[PM2][ERROR] No processes saved; DUMP file doesn't exist

so i am unable to access my backend,which is running on http port.
<p>on github actions this file is executing successfully by starting pm2 instance as service but when in login to my ssh server and run command "pm2 ls" it does not list any pm2 instance as service.</p>
<p>here is my github actions workflow yml file:</p>
<pre><code>name: Deploy Backend Test Environment
on:
push:
branches:
- backend-dev
jobs:
deploy:
runs-on: self-hosted
defaults:
run:
# shell: bash -l {0}
working-directory: backend
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install PM2 globally
run: npm install -g pm2

- name: Install dependencies
run: npm install --legacy-peer-deps

- name: starting backend
run: npm run pm2dev
</code></pre>
<p>here are my package.json scripts which are being used in above workflow file:</p>
<pre><code>"scripts": {
"start": "env-cmd -f .env.prod nodemon --experimental-specifier-resolution=node server.js",
"dev": "env-cmd -f .env.dev nodemon --experimental-specifier-resolution=node server.js",
"list": "pm2 ls",
"pm2": "pm2 delete 3fi-backend || true && PORT=3001 env-cmd -f .env.prod pm2 start server.js --name 3fi-backend",
"pm2dev": "pm2 delete 3fi-backend-dev || true && PORT=3002 env-cmd -f .env.dev pm2 start server.js --name 3fi-backend-dev"
},
</code></pre>
<blockquote>
<p>on github actions this file is executing successfully by starting pm2
instance as service but when in login to my ssh server and run command
"pm2 ls" it does not list any pm2 instance as service.</p>
</blockquote>
<p>so i updated these in workflow file:</p>
<pre><code>- name: Start backend
run: |
export PM2_HOME=$(pwd)/.pm2
npm run pm2dev
pm2 save --force
</code></pre>
<p>here are pm2 logs on github actions cli after adding <code>export PM2_HOME=$(pwd)/.pm2</code></p>
<pre><code>Run export PM2_HOME=$(pwd)/.pm2

Lifecycle scripts included in [email protected]:
start
env-cmd -f .env.prod nodemon --experimental-specifier-resolution=node server.js
available via npm run-script:
dev
env-cmd -f .env.dev nodemon --experimental-specifier-resolution=node server.js
list
pm2 ls
pm2
pm2 delete 3fi-backend || true && PORT=3001 env-cmd -f .env.prod pm2 start server.js --name 3fi-backend
pm2dev
pm2 delete 3fi-backend-dev || true && PORT=3002 env-cmd -f .env.dev pm2 start server.js --name 3fi-backend-dev
-------------
__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
_\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
_\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
_\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
_\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
_\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
_\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
_\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
_\///______________\///______________\///__\///////////////__
Runtime Edition
PM2 is a Production Process Manager for Node.js applications
with a built-in Load Balancer.
Start and Daemonize any application:
$ pm2 start app.js
Load Balance 4 instances of api.js:
$ pm2 start api.js -i 4
Monitor in production:
$ pm2 monitor
Make pm2 auto-boot at server restart:
$ pm2 startup
To go further checkout:
http://pm2.io/
-------------
[PM2] Spawning PM2 daemon with pm2_home=/home/ubuntu/actions-runner/_work/landing_page_v2/landing_page_v2/backend/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Saving current process list...
[PM2] Successfully saved in /home/ubuntu/actions-runner/_work/landing_page_v2/landing_page_v2/backend/.pm2/dump.pm2
</code></pre>
<p>it seems on github actions context of pm2 home is</p>
<pre><code>/home/ubuntu/actions-runner/_work/landing_page_v2/landing_page_v2/backend/.pm2/dump.pm2
</code></pre>
<p>but when in run "<code>pm2 resurrect"</code> on ssh server i get following logs:</p>
<pre><code>[PM2] Resurrecting
[PM2] Restoring processes located in /home/ubuntu/.pm2/dump.pm2
[PM2][ERROR] Failed to read dump file in /home/ubuntu/.pm2/dump.pm2
[PM2] Restoring processes located in /home/ubuntu/.pm2/dump.pm2.bak
[PM2][ERROR] Failed to read dump file in /home/ubuntu/.pm2/dump.pm2.bak
[PM2][ERROR] No processes saved; DUMP file doesn't exist
</code></pre>
<p>so i am unable to access my backend,which is running on http port.</p>
Continue reading...
 

Latest posts

M
Replies
0
Views
1
Meliodas Dragon
M
Top