﷽
This is just short information howto replace supervisord with pm2 to run node or apps.
Install pm2 :
# npm install pm2 -g
# su appadm
Previous supervisord config :
$ cat /etc/supervisor/conf.d/apps-fe.conf
[program:apps-fe]
directory=/home/appadm/apps/apps-frontend/
command=npm run start
autostart=true
autorestart=true
startretries=30
user=appadm
stderr_logfile=/var/log/apps-fe.log
$ cat /etc/supervisor/conf.d/apps-be.conf
[program:apps-be]
directory=/home/appadm/apps/apps-backend/
command=npm run start
autostart=true
autorestart=true
startretries=30
user=appadm
stderr_logfile=/var/log/apps-be.log
Run with least privilege :
# su appadm
$ whoami
appadm
$ cd /home/appadm/apps/apps-frontend/
$ pm2 start --name=apps-fe npm -- start
[PM2] Starting /usr/local/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ apps-fe │ default │ N/A │ fork │ 3057481 │ 0s │ 0 │ online │ 0% │ 27.0mb │ apps… │ disabled │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App apps-be differs. Type 'pm2 save' to synchronize.
$ cd /home/appadm/apps/apps-backend/
$ pm2 start --name=apps-be npm -- start
[PM2] Starting /usr/local/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ apps-be │ default │ N/A │ fork │ 3057534 │ 0s │ 0 │ online │ 0% │ 20.0mb │ apps… │ disabled │
│ 0 │ apps-fe │ default │ N/A │ fork │ 3057481 │ 16s │ 0 │ online │ 0% │ 57.0mb │ apps… │ disabled │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
$ pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /home/appadm/.pm2/dump.pm2
$ pm2 status
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ apps-be │ default │ N/A │ fork │ 3057534 │ 5m │ 0 │ online │ 0% │ 59.9mb │ apps… │ disabled │
│ 0 │ apps-fe │ default │ N/A │ fork │ 3057481 │ 6m │ 0 │ online │ 0% │ 58.0mb │ apps… │ disabled │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
To restart :
$ pm2 restart 'id'
for example to restart apps-fe :
$ pm2 restart 0
That's it hope it useful.
No comments:
Post a Comment