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/master/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://app.travis-ci.com/github/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://github.com/nvm-sh/nvm#installing-and-updating) 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-ls-v2.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 | [More about Process Management](https://pm2.keymetrics.io/docs/usage/process-management/)
|
103 |
|
104 | ### Cluster Mode: Node.js Load Balancing & Zero Downtime Reload
|
105 |
|
106 | 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).
|
107 |
|
108 | ![Framework supported](https://raw.githubusercontent.com/Unitech/PM2/master/pres/cluster.png)
|
109 |
|
110 | Starting a Node.js application in cluster mode that will leverage all CPUs available:
|
111 |
|
112 | ```bash
|
113 | $ pm2 start api.js -i <processes>
|
114 | ```
|
115 |
|
116 | `<processes>` can be `'max'`, `-1` (all cpu minus 1) or a specified number of instances to start.
|
117 |
|
118 | **Zero Downtime Reload**
|
119 |
|
120 | Hot Reload allows to update an application without any downtime:
|
121 |
|
122 | ```bash
|
123 | $ pm2 reload all
|
124 | ```
|
125 |
|
126 | [More informations about how PM2 make clustering easy](https://pm2.keymetrics.io/docs/usage/cluster-mode/)
|
127 |
|
128 | ### Container Support
|
129 |
|
130 | With the drop-in replacement command for `node`, called `pm2-runtime`, run your Node.js application in a hardened production environment.
|
131 | Using it is seamless:
|
132 |
|
133 | ```
|
134 | RUN npm install pm2 -g
|
135 | CMD [ "pm2-runtime", "npm", "--", "start" ]
|
136 | ```
|
137 |
|
138 | [Read More about the dedicated integration](https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/)
|
139 |
|
140 | ### Host monitoring speedbar
|
141 |
|
142 | PM2 allows to monitor your host/server vitals with a monitoring speedbar.
|
143 |
|
144 | To enable host monitoring:
|
145 |
|
146 | ```bash
|
147 | $ pm2 set pm2:sysmonit true
|
148 | $ pm2 update
|
149 | ```
|
150 |
|
151 | ![Framework supported](https://raw.githubusercontent.com/Unitech/PM2/master/pres/vitals.png)
|
152 |
|
153 | ### Terminal Based Monitoring
|
154 |
|
155 | ![Monit](https://github.com/Unitech/pm2/raw/master/pres/pm2-monit.png)
|
156 |
|
157 | Monitor all processes launched straight from the command line:
|
158 |
|
159 | ```bash
|
160 | $ pm2 monit
|
161 | ```
|
162 |
|
163 | ### Log Management
|
164 |
|
165 | To consult logs just type the command:
|
166 |
|
167 | ```bash
|
168 | $ pm2 logs
|
169 | ```
|
170 |
|
171 | Standard, Raw, JSON and formated output are available.
|
172 |
|
173 | Examples:
|
174 |
|
175 | ```bash
|
176 | $ pm2 logs APP-NAME # Display APP-NAME logs
|
177 | $ pm2 logs --json # JSON output
|
178 | $ pm2 logs --format # Formated output
|
179 |
|
180 | $ pm2 flush # Flush all logs
|
181 | $ pm2 reloadLogs # Reload all logs
|
182 | ```
|
183 |
|
184 | To enable log rotation install the following module
|
185 |
|
186 | ```bash
|
187 | $ pm2 install pm2-logrotate
|
188 | ```
|
189 |
|
190 | [More about log management](https://pm2.keymetrics.io/docs/usage/log-management/)
|
191 |
|
192 | ### Startup Scripts Generation
|
193 |
|
194 | PM2 can generate and configure a Startup Script to keep PM2 and your processes alive at every server restart.
|
195 |
|
196 | Init Systems Supported: **systemd**, **upstart**, **launchd**, **rc.d**
|
197 |
|
198 | ```bash
|
199 | # Generate Startup Script
|
200 | $ pm2 startup
|
201 |
|
202 | # Freeze your process list across server restart
|
203 | $ pm2 save
|
204 |
|
205 | # Remove Startup Script
|
206 | $ pm2 unstartup
|
207 | ```
|
208 |
|
209 | [More about Startup Scripts Generation](https://pm2.keymetrics.io/docs/usage/startup/)
|
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).
|