> ## Content Index
> Fetch the complete content index at: https://sleepyforest.magicbytes.top/llms.txt
> Use this file to discover other available public pages before exploring further.

# PM2 cheat sheet
- URL: https://sleepyforest.magicbytes.top/pm2-cheat-sheet/
- Published: 2021-08-23T07:39:54.000Z
- Updated: 2021-10-03T02:30:59.000Z
- Description: PM2 cheat sheet (site/app management) (auto restart on server boot)
- Author: Betty
- Tags: Tech, 笔记, 备忘单, #Import 2026-08-29 09:17

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

```