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