By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
IT Infras HolicIT Infras HolicIT Infras Holic
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Search
  • Privacy Policy
© 2024. All Rights Reserved.
Font ResizerAa
IT Infras HolicIT Infras Holic
Font ResizerAa
  • News
  • Linux
  • Docker
  • Web Server
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
Search
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Follow US
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
IT Infras Holic > Blog > Linux > Application > Java Process Manager 2 (PM2) Cheat Sheet
ApplicationLinux

Java Process Manager 2 (PM2) Cheat Sheet

writer
Share
4 Min Read
SHARE

Java Process Manager 2 (PM2)

PM2 is a production java 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.

Contents
Java Process Manager 2 (PM2)#Installation#Start an app# Specify an app name# Watch and Restart app when files change# Set memory threshold for app reload# Specify log file# Pass extra arguments to the script# Delay between automatic restarts# Prefix logs with time# Do not auto restart app# Specify cron for forced restart# Attach to application log#Managing processes#List managed applications#Display logs#Terminal Based Dashboard#Cluster mode#Restart application on changes#Updating PM2CheatSheet Java Process Manager 2# Fork mode# Cluster mode# Listing# Logs# Actions# Misc

#Installation

1
npm install pm2@latest -g

 

#Start an app

1
2
3
4
pm2 start app.js
pm2 start bashscript.sh
pm2 start python-app.py --watch
pm2 start binary-file -- --port 1520

 

# Specify an app name

1
--name <app_name>

 

# Watch and Restart app when files change

1
--watch

 

# Set memory threshold for app reload

1
--max-memory-restart <200MB>

 

# Specify log file

1
--log <log_path>

 

# Pass extra arguments to the script

1
-- arg1 arg2 arg3

# Delay between automatic restarts

1
--restart-delay <delay in ms>

 

# Prefix logs with time

1
--time

 

# Do not auto restart app

1
--no-autorestart

 

# Specify cron for forced restart

1
--cron <cron_pattern>

 

# Attach to application log

1
--no-daemon

 

#Managing processes

1
2
3
4
pm2 restart app_name
pm2 reload app_name
pm2 stop app_name
pm2 delete app_name

 

#List managed applications

1
pm2 [list|ls|status]

 

#Display logs

1
2
pm2 logs
pm2 logs --lines 200

 

#Terminal Based Dashboard

1
pm2 monit

 

#Cluster mode

1
pm2 start app.js -i max

 

#Restart application on changes

1
2
cd /path/to/my/app
pm2 start env.js --watch --ignore-watch="node_modules"

 

#Updating PM2

1
npm install pm2@latest -g &amp;&amp; pm2 update</code>py

 

CheatSheet Java Process Manager 2

 

# Fork mode

1
pm2 start app.js --name my-api # Name process</code>y

 

# Cluster mode

1
2
3
4
pm2 start app.js -i 0        # Will start maximum processes with LB depending on available CPUs
pm2 start app.js -i max      # Same as above, but deprecated.
pm2 scale app +3             # Scales `app` up by 3 workers
pm2 scale app 2              # Scales `app` up or down to 2 workers total

 

# Listing

1
2
3
4
5
6
7
pm2 list               # Display all processes status
pm2 jlist              # Print process list in raw JSON
pm2 prettylist         # Print process list in beautified JSON
 
pm2 describe 0         # Display all informations about a specific process
 
pm2 monit              # Monitor all processes

 

# Logs

1
2
3
pm2 logs [--raw]       # Display all processes logs in streaming
pm2 flush              # Empty all log files
pm2 reloadLogs         # Reload all logs

 

# Actions

1
2
3
4
5
6
7
8
9
10
pm2 stop all           # Stop all processes
pm2 restart all        # Restart all processes
 
pm2 reload all         # Will 0s downtime reload (for NETWORKED apps)
 
pm2 stop 0             # Stop specific process id
pm2 restart 0          # Restart specific process id
 
pm2 delete 0           # Will remove process from pm2 list
pm2 delete all         # Will remove all processes from pm2 list

 

# Misc

1
2
3
4
5
6
7
pm2 reset &lt;process&gt;    # Reset meta data (restarted time...)
pm2 updatePM2          # Update in memory pm2
pm2 ping               # Ensure pm2 daemon has been launched
pm2 sendSignal SIGUSR2 my-app # Send system signal to script
pm2 start app.js --no-daemon
pm2 start app.js --no-vizion
pm2 start app.js --no-autorestart

So, more understand about java process manager? Hoe you will understand how to use java process manager 2 or PM2

You Might Also Like

Monitoring File & Directory Changes using Bash Script

Vulnerability Checker CVE-2024-3094

Unleashing the Potential of Knowledge Management with Wiki.js

How to Install Apache Guacamole with Docker Compose

Unlocking Seamless Remote Access: Exploring the Power of Apache Guacamole

TAGGED: java, pm2
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Telegram Copy Link
Previous Article How to Clear Docker Logs and Activate Log Rotate How to Clear Docker Logs and Activate Log Rotate
Next Article Install RabbitMQ on CentOS 7 Install RabbitMQ on CentOS 7
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest News

bash
Monitoring File & Directory Changes using Bash Script
Linux Application
vulnerability
Vulnerability Checker CVE-2024-3094
Linux
wiki.js
Unleashing the Potential of Knowledge Management with Wiki.js
Application Linux
Install Apache Guacamole
How to Install Apache Guacamole with Docker Compose
Application Linux

You Might also Like

How to Install Cyberpanel on Ubuntu 22.04
OpenlitespeedUbuntuWeb Server

Install Cyberpanel on Ubuntu 22.04

8 Min Read
How to map SFTP as a drive on Windows 10
LinuxWindows

How to map SFTP as a drive on Windows 10

3 Min Read
Follow US
© 2024
activity notes activity notes
Welcome Back!

Sign in to your account

Lost your password?