Skip to content

recipes/pm2

View source on GitHub

typescript
import '@catapultjs/deploy/recipes/pm2'

Requires an ecosystem.config.cjs file at the root of the project.

Tasks

TaskInsertedDescription
pm2:startOrReloadafter deploy:publishStarts or reloads PM2 processes via startOrReload --update-env
pm2:saveafter pm2:startOrReloadPersists the PM2 process list
pm2:startStarts PM2 processes (manual)
pm2:reloadZero-downtime reload (manual)
pm2:restartHard restart (manual)
pm2:stopStops all processes (manual)
pm2:deleteDeletes all processes from PM2 (manual)
pm2:logsDisplays the last 50 lines of logs (manual)
pm2:listLists PM2 processes (manual)
pm2:showShows detailed info for each app in ecosystem.config.cjs (manual)

ecosystem.config.cjs must be present at the root of each release, because PM2 reads it from .

Inside that file, prefer absolute paths that resolve through current instead of paths tied to a specific release directory. This avoids keeping references to an old release after a new deployment.

Example:

js
const path = require('path')
const root = path.resolve(__dirname, '../', 'current')

module.exports = {
  apps: [
    {
      name: 'admin',
      exec_mode: 'fork',
      instances: 1,
      autorestart: true,
      watch: false,
      cwd: root,
      script: 'pnpm',
      args: 'run start',
      max_memory_restart: '1G',
    },
  ],
}

Stop, reload, restart and delete tasks use so they always target the active release.

Hooks

onStatus — displays the PM2 version during cata status.

Manual tasks can be run from the terminal:

bash
npx cata task pm2:reload
npx cata task pm2:logs --host staging