setup/doc/pm2.md

90 lines
2.3 KiB
Markdown
Raw Permalink Normal View History

2023-09-13 10:25:41 +02:00
# Setup pm2
2023-09-13 10:24:41 +02:00
* configure pm2 like [this](https://pm2.io/docs/runtime/guide/installation/) to start API on system startup
2024-04-10 12:49:16 +02:00
//OPTION: * with npm
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
npm install pm2 -g
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
//OPTION: * with GNU/Debian
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
sudo apt update && sudo apt install sudo curl && curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | sudo -E bash -
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
* logout and login in again to make the instructions above available
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
exit
ssh <user>@<host>
2023-09-13 10:24:41 +02:00
```
* verify installation of pm2
```
pm2 --version
```
* initialize pm2 as a startup service
```
pm2 startup
2024-04-10 12:49:16 +02:00
//ON-DEMAND: 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 <enter path>
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
# Options
* update pm2 with npm
```
npm install pm2 -g && pm2 update
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
* install pm2 autocompletion
```
pm2 completion install
2023-09-13 10:24:41 +02:00
```
2024-04-10 12:49:16 +02:00
* restart/logout/login your system, and check if all the serviceis running under PM2
2023-09-13 10:24:41 +02:00
```
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
```
2024-04-10 13:46:12 +02:00
pm2 show <id>
pm2 show <name>
2023-09-13 10:24:41 +02:00
```
* 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
```