From ca69a02987bc8c42aa40a49a9dbe9f2ab04ec130 Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Wed, 13 Sep 2023 10:24:41 +0200 Subject: [PATCH] doc: adjust doc/pm2.md --- doc/pm2.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/doc/pm2.md b/doc/pm2.md index 5661d63..9ea6c71 100644 --- a/doc/pm2.md +++ b/doc/pm2.md @@ -1,6 +1,104 @@ +# Setup pm2 (update Sep 2023) + +* configure pm2 like [this](https://pm2.io/docs/runtime/guide/installation/) to start API on system startup +``` +npm install pm2 -g +apt update && apt install sudo curl && curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | sudo -E bash - +``` + +* logout and login in again to make the instructions above available +``` +exit +ssh api-data.vbn.de@srv-web-01.vbn-gmbh.local +``` + +* install pm2 autocompletion +``` +pm2 completion install +``` + +* Update pm2 +``` +npm install pm2 -g && pm2 update +``` + +* verify installation of pm2 +``` +pm2 --version +``` + +* initialize pm2 as a startup service +``` +pm2 startup +``` + +* to setup the Startup Script, copy/paste the following command: +``` +sudo env PATH=$PATH:/home/api-data.vbn.de/.nvm/versions/node/v18.17.1/bin /home/api-data.vbn.de/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/bin/pm2 startup systemd -u api-data.vbn.de --hp /home/api-data.vbn.de +``` + +* start the service as npm start script with PM2 +``` +cd ~/git/data-api/ +grep start package.json +pm2 start --name api-data.vbn.de npm -- start --watch +``` + +* register/save the current list of processes you want to manage using PM2 so that they will re-spawn at system boot (every time it is expected or an unexpected server restart) +``` +pm2 save +``` + +* OPTION: restart/logout/login your system, and check if all the serviceis running under PM2 +``` +pm2 ls +``` +or +``` +pm2 status +``` + +* monitor logs, custom metrics, process information from all processes +``` +pm2 monit +``` + +* view details of a single Node process using the process ID or name +``` +pm2 show 0 +pm2 show api-data.vbn.de +``` + +* list of some common process (single or all) management command +``` +$ sudo pm2 stop all #stop all apps +$ sudo pm2 stop 0 #stop process with ID 0 +$ sudo pm2 restart all #restart all apps +$ sudo pm2 reset 0 #reset all counters +$ sudo pm2 delete all #kill and remove all apps +$ sudo pm2 delete 1 #kill and delete app with ID 1 +``` + +* manage application logs +``` +$ sudo pm2 logs #view logs for all processes +$ sudo pm2 logs 1 #view logs for app 1 +$ sudo pm2 logs --json #view logs for all processes in JSON format +$ sudo pm2 flush #flush all logs +``` + +* manage the PM2 process +``` +$ sudo pm2 startup #enable PM2 to start at system boot +$ sudo pm2 startup systemd #or explicitly specify systemd as startup system +$ sudo pm2 save #save current process list on reboot +$ sudo pm2 unstartup #disable PM2 from starting at system boot +$ sudo pm2 update #update PM2 package +``` + # Setup PM2 -* update Apt repository cache +* update Debian package repository cache ``` sudo apt update ```