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:
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:
"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:
- 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
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
/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:
[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.