pm2

参考文献

常用命令

  • 安装

    1
    2
    3
    $ npm install pm2@latest -g
    # or
    $ yarn global add pm2
  • 启动app

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    $ pm2 start app.js
    # 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
  • 管理

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    pm2 restart app:重启名称为“app”的应用程序。

    pm2 stop app:停止名称为“app”的应用程序。

    pm2 delete app:删除名称为“app”的应用程序。

    pm2 list:列出当前正在运行的应用程序。

    pm2 monit:实时监控所有应用程序的 CPU 和内存使用情况。

    pm2 logs:查看所有应用程序的日志输出。

    pm2 scale app 3:将名称为“app”的应用程序的工作进程数扩展到 3。

    pm2 reload app:重新加载名称为“app”的应用程序。

    pm2 save:将当前运行的应用程序保存到配置文件中。