Is it possible to add pre-restart script?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
Hello guys, I'm using pm2 with my services, and it has worked like a charm. π
I'm running a simple api backend service using nestjs, I set my command like npm run start in my ecosystem file.
And I know When I execute command pm2 restart api, short-term service-down would be inevitable.
To make that down-time to be shorter, I'm trying to change from npm run start to npm run start:prod because latter one just runs already built files. But to use start:prod, I have to execute npm run build first. --> Here is my issue.
It can be done just put build command inside ecosystem file (like npm run build && npm run start:prod), but that means service is stopped until build command is finished.
Is there any way to execute commands (here's like npm run build) before restart command?
How could we reproduce this issue?
None
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Mon Oct 19 2020 14:30:20 GMT+0900 (Korean Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 4.5.0
node version : 12.16.3
node path : /root/.nvm/versions/node/v12.16.3/bin/pm2
argv : /root/.nvm/versions/node/v12.16.3/bin/node,/root/.nvm/versions/node/v12.16.3/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : root
uid : 0
gid : 0
uptime : 147min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 4.5.0
node version : 12.16.3
node path : /root/.nvm/versions/node/v12.16.3/bin/pm2
argv : /root/.nvm/versions/node/v12.16.3/bin/node,/root/.nvm/versions/node/v12.16.3/bin/pm2,report
argv0 : node
user : root
uid : 0
gid : 0
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Xeon(R) CPU E5-2660 v4 @ 2.00GHz
cpus nb : 1
freemem : 972140544
totalmem : 2088349696
home : /root
===============================================================================
--- PM2 list -----------------------------------------------
βββββββ¬βββββββββββββββββββ¬ββββββββββββββ¬ββββββββββ¬ββββββββββ¬βββββββββββ¬βββββββββ¬βββββββ¬ββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ
β id β name β namespace β version β mode β pid β uptime β βΊ β status β cpu β mem β user β watching β
βββββββΌβββββββββββββββββββΌββββββββββββββΌββββββββββΌββββββββββΌβββββββββββΌβββββββββΌβββββββΌββββββββββββΌβββββββββββΌβββββββββββΌβββββββββββΌβββββββββββ€
β 2 β api β default β 0.35.1 β fork β 10059 β 9m β 7 β online β 0.1% β 44.8mb β root β disabled β
βββββββ΄βββββββββββββββββββ΄ββββββββββββββ΄ββββββββββ΄ββββββββββ΄βββββββββββ΄βββββββββ΄βββββββ΄ββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ
Module
ββββββ¬ββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββ¬ββββββββ¬βββββββββββ¬βββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ
β id β module β version β pid β status β βΊ β cpu β mem β user β
ββββββΌββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββΌββββββββΌβββββββββββΌβββββββΌβββββββββββΌβββββββββββΌβββββββββββ€
β 1 β pm2-logrotate β 2.7.0 β 3444 β online β 0 β 0.2% β 48.5mb β root β
ββββββ΄ββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββ΄ββββββββ΄βββββββββββ΄βββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2 | 2020-10-19T12:58:55: PM2 log: Stopping app:api id:2
PM2 | 2020-10-19T12:58:55: PM2 log: App [api:2] exited with code [0] via signal [SIGINT]
PM2 | 2020-10-19T12:58:55: PM2 log: pid=6112 msg=process killed
PM2 | 2020-10-19T12:58:55: PM2 log: App [api:2] starting in -fork mode-
PM2 | 2020-10-19T12:58:55: PM2 log: App [api:2] online
PM2 | 2020-10-19T14:17:14: PM2 log: Stopping app:api id:2
PM2 | 2020-10-19T14:17:14: PM2 log: App [api:2] exited with code [0] via signal [SIGINT]
PM2 | 2020-10-19T14:17:14: PM2 log: pid=6460 msg=process killed
PM2 | 2020-10-19T14:17:14: PM2 log: App [api:2] starting in -fork mode-
PM2 | 2020-10-19T14:17:14: PM2 log: App [api:2] online
PM2 | 2020-10-19T14:17:21: PM2 log: Stopping app:api id:2
PM2 | 2020-10-19T14:17:22: PM2 log: App [api:2] exited with code [0] via signal [SIGINT]
PM2 | 2020-10-19T14:17:22: PM2 log: pid=9765 msg=process killed
PM2 | 2020-10-19T14:17:22: PM2 log: App [api:2] starting in -fork mode-
PM2 | 2020-10-19T14:17:22: PM2 log: App [api:2] online
PM2 | 2020-10-19T14:21:06: PM2 log: Stopping app:api id:2
PM2 | 2020-10-19T14:21:06: PM2 log: App [api:2] exited with code [0] via signal [SIGINT]
PM2 | 2020-10-19T14:21:06: PM2 log: pid=9814 msg=process killed
PM2 | 2020-10-19T14:21:06: PM2 log: App [api:2] starting in -fork mode-
PM2 | 2020-10-19T14:21:06: PM2 log: App [api:2] online
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up β it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names an ecosystem file and the npm run build, npm run start, and npm run start:prod commands, but no repository file or test. Start by tracing PM2's restart flow and ecosystem-file configuration; done means a documented pre-restart command can run before the service is stopped without leaving restart behavior ambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, devops
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100