1 | <div align="center">
|
2 | <br/>
|
3 | <a href="http://pm2.keymetrics.io/" title="PM2 Keymetrics link">
|
4 | <img width=710px src="https://raw.githubusercontent.com/Unitech/pm2/development/pres/pm2-v4.png" alt="pm2 logo">
|
5 | </a>
|
6 | <br/>
|
7 | <br/>
|
8 | <b>P</b>(rocess) <b>M</b>(anager) <b>2</b><br/>
|
9 | <i>Runtime Edition</i>
|
10 | <br/><br/>
|
11 |
|
12 |
|
13 | <a title="PM2 Downloads">
|
14 | <img src="https://img.shields.io/npm/dm/pm2" alt="Downloads per Month"/>
|
15 | </a>
|
16 |
|
17 | <a title="PM2 Downloads">
|
18 | <img src="https://img.shields.io/npm/dy/pm2" alt="Downloads per Year"/>
|
19 | </a>
|
20 |
|
21 | <a href="https://badge.fury.io/js/pm2" title="NPM Version Badge">
|
22 | <img src="https://badge.fury.io/js/pm2.svg" alt="npm version">
|
23 | </a>
|
24 |
|
25 | <a href="https://travis-ci.com/github/Unitech/pm2" title="PM2 Tests">
|
26 | <img src="https://travis-ci.org/Unitech/pm2.svg?branch=master" alt="Build Status"/>
|
27 | </a>
|
28 |
|
29 | <br/>
|
30 | <br/>
|
31 | <br/>
|
32 | </div>
|
33 |
|
34 |
|
35 | PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
|
36 |
|
37 | Starting an application in production mode is as easy as:
|
38 |
|
39 | ```bash
|
40 | $ pm2 start app.js
|
41 | ```
|
42 |
|
43 | PM2 is constantly assailed by [more than 1800 tests](https://travis-ci.org/Unitech/pm2).
|
44 |
|
45 | Official website: [https://pm2.keymetrics.io/](https://pm2.keymetrics.io/)
|
46 |
|
47 | Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 12.X.
|
48 |
|
49 |
|
50 | ### Installing PM2
|
51 |
|
52 | With NPM:
|
53 |
|
54 | ```bash
|
55 | $ npm install pm2 -g
|
56 | ```
|
57 |
|
58 | You can install Node.js easily with [NVM](https://riptutorial.com/node-js/example/4578/using-node-version-manager--nvm-) or [ASDF](https://blog.natterstefan.me/how-to-use-multiple-node-version-with-asdf)
|
59 |
|
60 | ### Start an application
|
61 |
|
62 | You can start any application (Node.js, Python, Ruby, binaries in $PATH...) like that:
|
63 |
|
64 | ```bash
|
65 | $ pm2 start app.js
|
66 | ```
|
67 |
|
68 | Your app is now daemonized, monitored and kept alive forever.
|
69 |
|
70 | ### Managing Applications
|
71 |
|
72 | Once applications are started you can manage them easily:
|
73 |
|
74 | ![Process listing](https://github.com/unitech/pm2/raw/master/pres/pm2-list.png)
|
75 |
|
76 | To list all running applications:
|
77 |
|
78 | ```bash
|
79 | $ pm2 list
|
80 | ```
|
81 |
|
82 | Managing apps is straightforward:
|
83 |
|
84 | ```bash
|
85 | $ pm2 stop <app_name|namespace|id|'all'|json_conf>
|
86 | $ pm2 restart <app_name|namespace|id|'all'|json_conf>
|
87 | $ pm2 delete <app_name|namespace|id|'all'|json_conf>
|
88 | ```
|
89 |
|
90 | To have more details on a specific application:
|
91 |
|
92 | ```bash
|
93 | $ pm2 describe <id|app_name>
|
94 | ```
|
95 |
|
96 | To monitor logs, custom metrics, application information:
|
97 |
|
98 | ```bash
|
99 | $ pm2 monit
|
100 | ```
|
101 |
|
102 |
|
103 | [More about Process Management](https://pm2.keymetrics.io/docs/usage/process-management/)
|
104 |
|
105 | ### Cluster Mode: Node.js Load Balancing & Zero Downtime Reload
|
106 |
|
107 | The Cluster mode is a special mode when starting a Node.js application, it starts multiple processes and load-balance HTTP/TCP/UDP queries between them. This increase overall performance (by a factor of x10 on 16 cores machines) and reliability (faster socket re-balancing in case of unhandled errors).
|
108 |
|
109 | Starting a Node.js application in cluster mode that will leverage all CPUs available:
|
110 |
|
111 | ```bash
|
112 | $ pm2 start api.js -i <processes>
|
113 | ```
|
114 |
|
115 | `<processes>` can be `'max'`, `-1` (all cpu minus 1) or a specified number of instances to start.
|
116 |
|
117 | **Zero Downtime Reload**
|
118 |
|
119 | Hot Reload allows to update an application without any downtime:
|
120 |
|
121 | ```bash
|
122 | $ pm2 reload all
|
123 | ```
|
124 |
|
125 | Seamlessly supported by all major Node.js frameworks and any Node.js applications without any code change:
|
126 |
|
127 | ![Framework supported](https://raw.githubusercontent.com/Unitech/PM2/master/pres/cluster-support.png)
|
128 |
|
129 | [More informations about how PM2 make clustering easy](https://pm2.keymetrics.io/docs/usage/cluster-mode/)
|
130 |
|
131 | ### Container Support
|
132 |
|
133 | With the drop-in replacement command for `node`, called `pm2-runtime`, run your Node.js application in a hardened production environment.
|
134 | Using it is seamless:
|
135 |
|
136 | ```
|
137 | RUN npm install pm2 -g
|
138 | CMD [ "pm2-runtime", "npm", "--", "start" ]
|
139 | ```
|
140 |
|
141 | [Read More about the dedicated integration](https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/)
|
142 |
|
143 | ### Terminal Based Monitoring
|
144 |
|
145 | ![Monit](https://github.com/Unitech/pm2/raw/master/pres/pm2-monit.png)
|
146 |
|
147 | Monitor all processes launched straight from the command line:
|
148 |
|
149 | ```bash
|
150 | $ pm2 monit
|
151 | ```
|
152 |
|
153 | ### Log Management
|
154 |
|
155 | To consult logs just type the command:
|
156 |
|
157 | ```bash
|
158 | $ pm2 logs
|
159 | ```
|
160 |
|
161 | Standard, Raw, JSON and formated output are available.
|
162 |
|
163 | Examples:
|
164 |
|
165 | ```bash
|
166 | $ pm2 logs APP-NAME # Display APP-NAME logs
|
167 | $ pm2 logs --json # JSON output
|
168 | $ pm2 logs --format # Formated output
|
169 |
|
170 | $ pm2 flush # Flush all logs
|
171 | $ pm2 reloadLogs # Reload all logs
|
172 | ```
|
173 |
|
174 | [More about log management](https://pm2.keymetrics.io/docs/usage/log-management/)
|
175 |
|
176 | ### Startup Scripts Generation
|
177 |
|
178 | PM2 can generates and configure a Startup Script to keep PM2 and your processes alive at every server restart.
|
179 |
|
180 | Init Systems Supported: **systemd**, **upstart**, **launchd**, **rc.d**
|
181 |
|
182 | ```bash
|
183 | # Generate Startup Script
|
184 | $ pm2 startup
|
185 |
|
186 | # Freeze your process list across server restart
|
187 | $ pm2 save
|
188 |
|
189 | # Remove Startup Script
|
190 | $ pm2 unstartup
|
191 | ```
|
192 |
|
193 | [More about Startup Scripts Generation](https://pm2.keymetrics.io/docs/usage/startup/)
|
194 |
|
195 | ### PM2 Modules
|
196 |
|
197 | PM2 embeds a simple and powerful module system. Installing a module is straightforward:
|
198 |
|
199 | ```bash
|
200 | $ pm2 install <module_name>
|
201 | ```
|
202 |
|
203 | Here are some PM2 compatible modules (standalone Node.js applications managed by PM2):
|
204 |
|
205 | [**pm2-logrotate**](https://www.npmjs.com/package/pm2-logrotate) automatically rotate logs and limit logs size<br/>
|
206 | [**pm2-server-monit**](https://www.npmjs.com/package/pm2-server-monit) monitor the current server with more than 20+ metrics and 8 actions<br/>
|
207 |
|
208 | ### Updating PM2
|
209 |
|
210 | ```bash
|
211 | # Install latest PM2 version
|
212 | $ npm install pm2@latest -g
|
213 | # Save process list, exit old PM2 & restore all processes
|
214 | $ pm2 update
|
215 | ```
|
216 |
|
217 | *PM2 updates are seamless*
|
218 |
|
219 | ## PM2+ Monitoring
|
220 |
|
221 | If you manage your apps with PM2, PM2+ makes it easy to monitor and manage apps across servers.
|
222 |
|
223 | ![https://app.pm2.io/](https://pm2.io/img/app-overview.png)
|
224 |
|
225 | Feel free to try it:
|
226 |
|
227 | [Discover the monitoring dashboard for PM2](https://app.pm2.io/)
|
228 |
|
229 | Thanks in advance and we hope that you like PM2!
|
230 |
|
231 | ## CHANGELOG
|
232 |
|
233 | [CHANGELOG](https://github.com/Unitech/PM2/blob/master/CHANGELOG.md)
|
234 |
|
235 | ## Contributors
|
236 |
|
237 | [Contributors](http://pm2.keymetrics.io/hall-of-fame/)
|
238 |
|
239 | ## License
|
240 |
|
241 | PM2 is made available under the terms of the GNU Affero General Public License 3.0 (AGPL 3.0).
|
242 | For other licenses [contact us](mailto:contact@keymetrics.io).
|