PM2 cheat sheet

PM2 cheat sheet (site/app management) (auto restart on server boot)

Get into the site directory.

Install PM2

yarn global add pm2

Basics

# to start the app with yarn
pm2 start 'yarn some_script_name' --name 'name to show in pm2'

# start from js
pm2 start app.js

# other examples
pm2 start bashscript.sh
pm2 start python-app.py --watch
pm2 start binary-file -- --port 1520

# to persist the app / auto start-up on boot
pm2 save

# show apps managed by pm2
pm2 list

# manage apps
pm2 restart app_name_or_id
pm2 reload app_name_or_id
pm2 stop app_name_or_id
pm2 delete app_name_or_id # delete from pm2 list

Some other options

# Specify an app name
--name <app_name>

# Watch and Restart app when files change
--watch

# Set memory threshold for app reload
--max-memory-restart <200MB>

# Specify log file
--log <log_path>

# Pass extra arguments to the script
-- arg1 arg2 arg3

# Delay between automatic restarts
--restart-delay <delay in ms>

# Prefix logs with time
--time

# Do not auto restart app
--no-autorestart

# Specify cron for forced restart
--cron <cron_pattern>

# Attach to application log
--no-daemon