home / skills / viteinfinite / skills / pm2-server-control

pm2-server-control skill

/skills/pm2-server-control

This skill helps you manage a local server with PM2 by starting, stopping, and monitoring status, logs, and cleanup.

npx playbooks add skill viteinfinite/skills --skill pm2-server-control

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.6 KB
---
name: pm2-server-control
description: >-
  Start and stop a server with pm2 using `pm2 start ./my-server --name <name> --no-autorestart`,
  plus common supporting commands for status, logs, restart, and cleanup.
metadata:
  owner: local
  version: 1
---

# pm2-server-control

Use this skill when the task requires starting or stopping a local server via PM2,
specifically using `pm2 start ./my-server --name <name> --no-autorestart`, and when
you need to inspect status or logs, restart, or clean up the process.

## Required command pattern

Always start the server with:

```bash
pm2 start ./my-server --name <name> --no-autorestart
```

Replace `<name>` with a concise, unique name (e.g., `api-dev`, `web-preview`).

## Useful PM2 commands

Start:

```bash
pm2 start ./my-server --name <name> --no-autorestart
```

Stop:

```bash
pm2 stop <name>
```

Restart (if a fresh start is needed):

```bash
pm2 restart <name>
```

Delete (remove from PM2 list):

```bash
pm2 delete <name>
```

List all processes:

```bash
pm2 list
```

Show detailed info:

```bash
pm2 show <name>
```

Logs (stream):

```bash
pm2 logs <name>
```

Logs (last N lines):

```bash
pm2 logs <name> --lines 200
```

Flush logs (if they get noisy):

```bash
pm2 flush <name>
```

Save current process list (optional, if asked):

```bash
pm2 save
```

Resurrect saved processes (only if asked):

```bash
pm2 resurrect
```

## Safety and cleanup

- Prefer `pm2 stop <name>` for normal shutdowns.
- Use `pm2 delete <name>` when the process is no longer needed.
- Keep process names stable across start/stop cycles.

Overview

This skill manages local Node servers using PM2 with a prescribed start command and a small set of supporting controls. It focuses on starting processes with --no-autorestart, inspecting status and logs, performing restarts, and cleaning up processes when they are no longer needed. It is optimized for predictable, manual server lifecycle operations in development and preview environments.

How this skill works

I always start servers using the exact command: pm2 start ./my-server --name <name> --no-autorestart so the process is registered under a clear, stable name and does not auto-restart. From there I use PM2 commands to stop, restart, delete, inspect, stream logs, flush noisy logs, and optionally save or resurrect the process list when requested. The skill favors explicit stop and delete actions for safe cleanup and stable naming across cycles.

When to use it

  • When you need to start a local server under PM2 with no automatic restarts (development or preview servers).
  • When you need to inspect process status, metadata, or streaming logs for debugging.
  • When you want to perform a controlled restart or full removal of the process from PM2.
  • When logs are noisy and need flushing or when you need recent log lines for investigation.
  • When you occasionally want to save or resurrect a curated process list (only if asked).

Best practices

  • Always use a concise, unique name (e.g., api-dev, web-preview) in the --name argument.
  • Prefer pm2 stop <name> for normal shutdowns and pm2 delete <name> when removing the process entirely.
  • Keep process names stable across start/stop cycles to avoid confusion and orphaned entries.
  • Use pm2 logs <name> for live debugging and pm2 logs <name> --lines N for recent history.
  • Flush logs with pm2 flush <name> if log files grow noisy before restarting or debugging.

Example use cases

  • Start a preview server for testing a pull request: pm2 start ./my-server --name web-preview --no-autorestart.
  • Stream logs while reproducing a bug: pm2 logs api-dev.
  • Perform a clean teardown after testing: pm2 stop api-dev && pm2 delete api-dev.
  • Get process details before deploying changes: pm2 show web-preview.
  • Retrieve recent logs for a failure investigation: pm2 logs api-dev --lines 200.

FAQ

Why use --no-autorestart?

It prevents PM2 from automatically restarting the process so you can inspect failures or manage restarts manually during development.

When should I run pm2 save or pm2 resurrect?

Only use pm2 save when you intentionally want the current process list persisted across system restarts; use pm2 resurrect to restore that saved list when explicitly required.