Pm2-node Application Process Manager

Source: Internet
Author: User
Tags memory usage cpu usage port number

The PM2 is a process manager for a node app with load-balancing capabilities. PM2 is perfect when you want to take advantage of all of your standalone code on all the CPUs on the server and ensure that the process is always alive, with 0 seconds of overloading. installation

NPM install-g PM2
usage
$ npm Install pm2-g     # command line installation PM2 
$ pm2 Start app.js-i 4  # background Run PM2, start 4 app.js 
                         # You can also pass the ' max ' parameter to start
                         # The correct number of processes depends on the core number of CPUs
$ pm2 start app.js--name My-api # named Process
$ PM2 List               # Show all process status
$ PM2 monit              # Monitor all incoming  Process
$ PM2 Logs               # Show all process logs
$ pm2 Stop           All # Stop all processes
$ pm2 Restart all        # restart all processes
$ PM2 Reload All         # 0-Second downtime reload process (for networked process)
$ pm2 Stop 0             # Stop the specified process
$ pm2 Restart 0          # Restart the specified process
$ PM2 St  Artup            # Generate init script keep process alive
$ PM2 Web                # Run robust computer API endpoint (http://localhost:9615)
$ PM2 Delete 0           # kills the specified process
$ pm2 Delete         All # kills all processes
different ways to run a process
$ pm2 start app.js-i max # Start maximum number of processes based on number of active CPUs $ PM2 start App.js-i 3 # Start 3 processes $ pm2 start app.js-x #用for K mode starts app.js instead of using cluster $ PM2 start app.js-x---a 23 # start app.js with fork mode and pass parameters (-a) $ pm2 start app.js--name SE Rverone # Start a process and name it ServerOne $ pm2 Stop ServerOne # stop ServerOne process $ pm2 Start App.json # boot process, in APP.J Son set options $ pm2 start app.js-i Max---a #在--pass parameters to App.js $ pm2 start app.js-i max-e err.log-o  Out.log # Launch and generate a profile you can also execute apps written in other languages (Fork mode): $ pm2 start my-bash-script.sh-x--interpreter bash $ pm2 start My-python-script.py-x--interpreter python 

0-Second downtime Overload: This feature allows you to reload the code without losing the request connection. Note: only available for Web apps running in Node 0.11.x version running in cluster mode (default mode)

$ PM2 Reload All

PM2 list: Lists all the process information that is managed by PM2, and also shows how many times a process will be started because of unhandled exceptions.

PM2 monit: Monitors the CPU and memory usage of each node process.

See the app launch details below:PM2 show launch name

View PM2 monit for application CPU usage

View PM2 app manifest pm2 list


PM2 can be used as a static file server

Here's how to start a static file server using PM2:

1 2 PM2 serve path port PM2 serve. 8000

This allows the static files under the current folder to run, and the port number is 8000, note. Start on behalf of the current resource directory

Also support the use of advanced, as follows

1 PM2 serve. 8000--name Express-Watch

This launches a static file server with the name Express, port number 8000, and listener file changes.


Article Source:

Http://www.expressjs.com.cn/advanced/pm.html

http://pm2.keymetrics.io/docs/usage/cluster-mode/

https://segmentfault.com/a/1190000002539204

https://www.douban.com/note/314200231/

https://blog.csdn.net/uikoo9/article/details/79018750

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.