Node.js / PM2 operations
v0.1.17PM2 process inventory + logs + per-app introspection, plus narrow mutators (restart, reload, stop, scale). Requires the runner to be the same uid as the PM2 daemon (or set PM2_HOME).
jq
node
pm2
Install
emisar pack install
fetches this pack, re-validates it, and verifies its content hash against the
--hash
below — the exact bytes this page was rendered against, so a tampered copy is
rejected — before copying it into the runner's packs dir. The command reloads a
running daemon itself; no manual restart.
sudo emisar pack install nodejs-pm2 --hash sha256:775e6f0096eb0a9d633495ae0e577ace6e0fb3be34e64a04d1569edff8618a59
Setup
Drives the local pm2 CLI on the runner host — no credentials needed.
Notes
- pm2 talks to a per-user daemon, so the runner must run as the same user that owns the target pm2 processes; running as a different uid (or root) sees a different, usually empty, process list.
-
If the apps run under a daemon at a non-default location, set PM2_HOME to that directory (and add it to the runner's
inherit_env).
Verify it works
Runs pm2.list, a low-risk
read that confirms the pack can reach its target. Run it on the host once the pack
is installed; pack install runs it for
you.
sudo emisar pack verify nodejs-pm2
Install and configure a pack walks through the whole sequence on a host.
Actions 15 total
View on GitHub-
pm2.describe exec low Low — read-only or trivially reversible
pm2 describe <name>
Show config + runtime details for one process (status, restarts, uptime, script path, resources). Read-only. Per-process environment is projected out — use `pm2.env` for one process's effective env.
View source on GitHub -
pm2.dump exec medium Medium — changes state, easily reversible
pm2 dump
Persist the current process list so PM2 resurrects it on boot.
View source on GitHub -
pm2.env exec high High — service-affecting
pm2 env <id>
Show effective environment for one process (post-merge of system + app env).
View source on GitHub -
pm2.error_logs exec medium Medium — changes state, easily reversible
pm2 logs <name> --err --lines N --nostream
Tail the last N stderr-only lines for one process.
View source on GitHub -
pm2.flush_logs exec medium Medium — changes state, easily reversible
pm2 flush <name>
Empty PM2 log files for one process. Existing log content is lost.
View source on GitHub -
pm2.jlist exec low Low — read-only or trivially reversible
pm2 jlist
List PM2 processes as JSON with status, uptime, restarts, mode, and CPU/mem. Read-only. Per-process environment is projected out — use `pm2.env` for one process's effective env.
View source on GitHub -
pm2.list exec low Low — read-only or trivially reversible
pm2 list
List all processes managed by PM2 with status, uptime, restarts, CPU/mem.
View source on GitHub -
pm2.logs exec medium Medium — changes state, easily reversible
pm2 logs <name> --lines N --nostream
Tail the last N stdout+stderr lines for one process.
View source on GitHub -
pm2.monit_snapshot exec low Low — read-only or trivially reversible
pm2 monit snapshot (CPU + memory)
Show one-shot CPU + memory snapshot for every process as JSON. Read-only. Per-process environment is projected out — use `pm2.env` for one process's effective env.
View source on GitHub -
pm2.node_version exec low Low — read-only or trivially reversible
node --version
Show Node.js runtime version (system default).
View source on GitHub -
pm2.pm2_version exec low Low — read-only or trivially reversible
pm2 -v
Show PM2 daemon version.
View source on GitHub -
pm2.reload exec high High — service-affecting
pm2 reload <name>
Zero-downtime reload — only safe for cluster-mode apps. For fork-mode, behaves like restart.
View source on GitHub -
pm2.restart exec high High — service-affecting
pm2 restart <name>
Hard-restart one process (kill + spawn). Drops in-flight requests.
View source on GitHub -
pm2.scale exec high High — service-affecting
pm2 scale <name> <N>
Set the number of cluster-mode workers for one app. No-op for fork mode.
View source on GitHub -
pm2.stop exec high High — service-affecting
pm2 stop <name>
Stop one process (PM2 won't auto-restart until you `start`/`restart`).
View source on GitHub