PM2 Common Command Usage Introduction

Source: Internet
Author: User
Tags json memory usage reset socket
PM2 is a process manager for a node app with load Balancing. When you want to take your standalone code all the CPUs on the server, and ensure that the process is always alive, 0 seconds of overloading, PM2 is perfect, let's look at PM2 commonly used command usage introduction bar.

PM2 (source on GitHub) is an open source Nodejs-based process manager, including daemon, monitor, log a complete set of functions, basically is the Nodejs application is the ideal daemon selection, in fact, it can not only start the Nodejs program, As long as it is a generic script program it can also be competent.


Here are the command lines commonly used by PM2

$ PM2 Start App.js # launch App.js application

$ PM2 Start app.js-i 4 # Cluster mode start 4 app.js Application Instances # 4 applications are automatically load balanced

$ PM2 Start app.js--name= "API" # launches the application and is named "API"

$ pm2 Start App.js--watch # Automatically restarts apps when files change

$ PM2 Start script.sh # launch Bash script


$ PM2 List # PM2 all applications launched

$ PM2 Monit # shows CPU and memory usage per application

$ PM2 Show [App-name] # Show all information about the application


$ PM2 Logs # show logs for all applications

$ PM2 logs [App-name] # Displays the log for the specified application

$ PM2 Flush


$ pm2 Stop all # to stop all applications

$ pm2 Stop 0 # Stop ID 0 for the specified application

$ pm2 Restart all # restart all apps

$ PM2 Reload All # Restart all apps in cluster mode

$ pm2 gracefulreload All # Graceful reload all apps in cluster mode

$ PM2 Delete all # Close and delete all apps

$ PM2 Delete 0 # Delete the specified app ID 0

$ PM2 Scale API 10 # Extend the app called API to 10 instances

$ PM2 Reset [app-name] # Reset Restart Quantity


$ PM2 Startup # Create a power-on self-start command

$ PM2 Save # Saves the current app list

$ PM2 Resurrect # reload saved apps list

$ PM2 Update # Save processes, kill PM2 and restore processes

$ PM2 Generate # Generate a sample JSON configuration file


$ PM2 Deploy App.json PROD Setup # Setup "prod" remote server

$ pm2 Deploy App.json prod # Update "prod" remote server

$ pm2 Deploy App.json prod revert 2 # revert "prod" remote server by 2


$ PM2 module:generate [name] # Generate sample module with name [name]

$ pm2 Install pm2-logrotate # Install module (here a log rotation system)

$ pm2 Uninstall pm2-logrotate # Uninstall module

$ PM2 Publish # Increment version, git push and NPM publish

Brief introduction

PM2 is a node process management tool that can be used to simplify many of the tedious tasks of node application management, such as performance monitoring, automatic restart, load balancing, and so on, and very simple to use.

The following is an introductory introduction to PM2, which basically covers the common functions and configurations of PM2. installation

A global installation is simply not easy. NPM install-g pm2 Directory Introduction

After the PM2 is installed, the following directory is created automatically. Look at the file name basically know what to do, it is not translated. $HOME/.pm2 would contain all PM2 related files $HOME/.pm2/logs would contain all applications logs $HOME/.pm2/pids would cont Ain all Applications PIDs $HOME/.pm2/pm2.log PM2 logs $HOME/.pm2/pm2.pid PM2 pid $HOME/.pm2/rpc.sock Socket file for Remot E commands $HOME/.pm2/pub.sock Socket file for publishable events $HOME/.pm2/conf.js PM2 Configuration Getting Started tutorial

Pick our favorite Express app for example. In general, we start the application via NPM start, which is actually called node./bin/www. So, PM2 is

Note that the--watch parameter is used here, which means that when your express application code changes, PM2 will help you restart the service, more intimate.

PM2 Start/bin/www--watch

It's so easy to get started, there's nothing to talk about. Directly on official documents: Http://pm2.keymetrics.io/docs/usage/quick-start common Command start

Parameter description:--watch: Monitor the application directory changes, once the change, automatic restart. If you want to accurately listen to, not hear the directory, it is best to pass the configuration file. -I--instances: How many instances are enabled for load balancing. If-I 0 or-I max, the number of instances is determined based on the current machine's number of cores. --ignore-watch: Exclude the Listening directory/file, can be a specific file name, or it can be regular. For example--ignore-watch= "test node_modules" Some scripts ""-N--name: The name of the app. You can use it when viewing your app's information. -O--output <path>: The path to the standard output log file. -e--error <path>: Error output log file path. --interpreter <interpreter

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.