|
5 | 5 | ### Quick start |
6 | 6 |
|
7 | 7 | - [Installation](#a1) |
| 8 | +- [Folder structure](#pm2-folder-structure) |
8 | 9 | - [Usage](#a2) |
9 | 10 | - [Examples](#a3) |
10 | 11 | - [Different ways to launch a process](#raw-examples) |
|
21 | 22 | - [Monitoring CPU/Memory usage](#a7) |
22 | 23 | - [Logs management](#a9) |
23 | 24 | - [Clustering](#a5) |
| 25 | +- [Multiple PM2 on the same server](#multiple-pm2) |
24 | 26 | - [Watch & Restart](#watch--restart) |
25 | 27 | - [Reloading without downtime](#hot-reload--0s-reload) |
26 | 28 | - [Make PM2 restart on server reboot](#a8) |
@@ -87,6 +89,19 @@ If the above fails use: |
87 | 89 | $ npm install git://github.com/Unitech/pm2#master -g |
88 | 90 | ``` |
89 | 91 |
|
| 92 | +<a name="pm2-folder-structure"/> |
| 93 | +## PM2 configuration folder structure |
| 94 | + |
| 95 | +Once PM2 is started, it automatically create these folders: |
| 96 | +- `$HOME/.pm2` will contain all PM2 related files |
| 97 | +- `$HOME/.pm2/logs` will contain all applications logs |
| 98 | +- `$HOME/.pm2/pids` will contain all applications pids |
| 99 | +- `$HOME/.pm2/pm2.log` PM2 logs |
| 100 | +- `$HOME/.pm2/pm2.pid` PM2 pid |
| 101 | +- `$HOME/.pm2/rpc.sock` Socket file for remote commands |
| 102 | +- `$HOME/.pm2/pub.sock` Socket file for publishable events |
| 103 | +- `$HOME/.pm2/conf.js` PM2 Configuration |
| 104 | + |
90 | 105 | <a name="a2"/> |
91 | 106 | ## Usage |
92 | 107 |
|
@@ -516,7 +531,7 @@ $ pm2 start big-array.js --max-memory-restart 20M |
516 | 531 | ### Programmatic |
517 | 532 |
|
518 | 533 | ``` |
519 | | -pm2.start({{ |
| 534 | +pm2.start({ |
520 | 535 | name : "max_mem", |
521 | 536 | script : "big-array.js", |
522 | 537 | max_memory_restart : "20M" |
@@ -583,17 +598,39 @@ Just use the `-u <username>` option ! |
583 | 598 | $ pm2 startup ubuntu -u www |
584 | 599 | ``` |
585 | 600 |
|
| 601 | +<a name="multiple-pm2"/> |
586 | 602 | ### Related commands |
587 | 603 |
|
588 | 604 | Dump all processes status and environment managed by PM2: |
| 605 | + |
589 | 606 | ```bash |
590 | | -$ pm2 dump |
| 607 | +$ pm2 [dump|save] |
591 | 608 | ``` |
| 609 | + |
592 | 610 | It populates the file `~/.pm2/dump.pm2` by default. |
593 | 611 |
|
594 | 612 | To bring back the latest dump: |
| 613 | + |
| 614 | +```bash |
| 615 | +$ pm2 resurrect |
| 616 | +``` |
| 617 | + |
| 618 | +## Multiple PM2 on the same server |
| 619 | + |
| 620 | +The client and daemon communicates via socket files available in $HOME/.pm2/[pub.sock|rpc.sock] |
| 621 | + |
| 622 | +You can start multiple PM2 instances by changing the `PM2_HOME` environmnent variable. |
| 623 | + |
595 | 624 | ```bash |
596 | | -$ pm2 [resurrect|save] |
| 625 | +$ PM2_HOME='.pm2' pm2 start echo.js --name="echo-node-1" |
| 626 | +$ PM2_HOME='.pm3' pm2 start echo.js --name="echo-node-2" |
| 627 | +``` |
| 628 | + |
| 629 | +This will start two different PM2 instances. To list processes managed by each different instances do: |
| 630 | + |
| 631 | +```bash |
| 632 | +$ PM2_HOME='.pm2' pm2 list |
| 633 | +$ PM2_HOME='.pm3' pm2 list |
597 | 634 | ``` |
598 | 635 |
|
599 | 636 | ## Watch & Restart |
@@ -638,8 +675,7 @@ var watch_options = { |
638 | 675 |
|
639 | 676 | ## JSON app declaration |
640 | 677 |
|
641 | | - |
642 | | -PM2 empowers your process management workflow, by allowing you to fine-tune the behavior, options, environment variables, logs files... of each process you need to manage via JSON configuration. |
| 678 | +PM2 empowers your process management workflow, by allowing you to fine-tune the behavior, options, environment variables, logs files... of each process you need to manage via JSON/JSON5/JS configuration. |
643 | 679 |
|
644 | 680 | It's particularly usefull for micro service based applications. |
645 | 681 |
|
@@ -680,11 +716,19 @@ $ pm2 start processes.json |
680 | 716 | # Stop |
681 | 717 | $ pm2 stop processes.json |
682 | 718 |
|
| 719 | +# Restart |
| 720 | +$ pm2 start processes.json |
| 721 | +## Or |
| 722 | +$ pm2 restart processes.json |
| 723 | + |
| 724 | +# Reload |
| 725 | +$ pm2 reload processes.json |
| 726 | + |
| 727 | +# Graceful Reload |
| 728 | +$ pm2 gracefulReload processes.json |
| 729 | + |
683 | 730 | # Delete from PM2 |
684 | 731 | $ pm2 delete processes.json |
685 | | - |
686 | | -# Restart all |
687 | | -$ pm2 restart processes.json |
688 | 732 | ``` |
689 | 733 |
|
690 | 734 | ### Options |
|
0 commit comments