|
1 | | -# spm |
| 1 | +# SPM — Simpler Process Manager |
2 | 2 |
|
3 | | -To install dependencies: |
| 3 | +A minimal process manager implementing a lean subset of [pm2](https://pm2.keymetrics.io/) features, with some extensions, designed for better development script setup. Lightweight, zero daemon, and ecosystem config compatible. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Start / Stop / Restart** — Manage multiple services from a single config |
| 8 | +- **Multi-instance** — Run multiple instances with port/env auto-increment |
| 9 | +- **Log management** — Tail, filter, flush, and rotate logs |
| 10 | +- **JSON output** — `jlist` for machine-readable status (CI/scripting) |
| 11 | +- **Log rotation** — Size-based rotation and retention with optional background watcher |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +npm install -g @hackmd/spm |
| 17 | +``` |
| 18 | + |
| 19 | +Or with Bun: |
| 20 | + |
| 21 | +```bash |
| 22 | +bun add -g @hackmd/spm |
| 23 | +``` |
| 24 | + |
| 25 | +## Quick Start |
| 26 | + |
| 27 | +1. Create an ecosystem config file (e.g. `ecosystem.config.js`) in your project: |
| 28 | + |
| 29 | +```javascript |
| 30 | +export default { |
| 31 | + apps: [ |
| 32 | + { |
| 33 | + name: 'api', |
| 34 | + script: 'node', |
| 35 | + args: 'server.js', |
| 36 | + instances: 2, |
| 37 | + env: { PORT: '3000' }, |
| 38 | + increment_vars: ['PORT'], |
| 39 | + }, |
| 40 | + { |
| 41 | + name: 'worker', |
| 42 | + script: 'node', |
| 43 | + args: 'worker.js', |
| 44 | + }, |
| 45 | + ], |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +2. Run SPM: |
4 | 50 |
|
5 | 51 | ```bash |
6 | | -bun install |
7 | | -bun run build |
| 52 | +spm start # Start all services |
| 53 | +spm start api # Start specific service |
| 54 | +spm list # List services and PIDs |
| 55 | +spm stop # Stop all |
| 56 | +spm restart api # Restart specific service |
| 57 | +spm logs api -t # Tail logs |
8 | 58 | ``` |
9 | 59 |
|
10 | | -Install locally global |
| 60 | +## Configuration |
| 61 | + |
| 62 | +| Option | Description | |
| 63 | +|--------|-------------| |
| 64 | +| `name` | Service identifier | |
| 65 | +| `script` | Command to run (e.g. `node`, `bun`, `python`) | |
| 66 | +| `args` | Arguments passed to the script | |
| 67 | +| `instances` | Number of instances (default: 1) | |
| 68 | +| `env` | Environment variables | |
| 69 | +| `increment_vars` | Env vars to increment per instance (e.g. `PORT`) | |
| 70 | + |
| 71 | +Config file is resolved from `./ecosystem.custom.config.js` by default. Override with `--config`: |
11 | 72 |
|
12 | 73 | ```bash |
13 | | -npm i . -g |
| 74 | +spm --config ./my-ecosystem.config.js start |
14 | 75 | ``` |
15 | 76 |
|
16 | | -## Shell completions |
| 77 | +## Commands |
| 78 | + |
| 79 | +| Command | Description | |
| 80 | +|---------|-------------| |
| 81 | +| `spm start [service]` | Start all or a specific service | |
| 82 | +| `spm stop [service]` | Stop processes (alias: `kill`) | |
| 83 | +| `spm restart [service]` | Restart processes | |
| 84 | +| `spm list` | List services and running PIDs | |
| 85 | +| `spm jlist` | JSON output of service status | |
| 86 | +| `spm logs [service]` | View logs (`-t` tail, `-n` lines, `-f` filter) | |
| 87 | +| `spm flush [service]` | Clear log files | |
| 88 | +| `spm rotate start` | Start log rotation watcher | |
| 89 | +| `spm rotate stop` | Stop rotation watcher | |
| 90 | + |
| 91 | +## Log Rotation |
| 92 | + |
| 93 | +Logs are stored in `~/.spm2/logs/`. Rotation: |
| 94 | + |
| 95 | +- Rotates when a log exceeds 10MB |
| 96 | +- Removes logs older than 3 days |
| 97 | +- Run `spm rotate start` for a background watcher |
| 98 | + |
| 99 | +## Shell Completions |
| 100 | + |
| 101 | +See [Yukaii/dotfiles](https://github.com/Yukaii/dotfiles/commit/569b50824c19340cefb308f385168492418f98e7) for shell completion setup. |
| 102 | + |
| 103 | +## License |
17 | 104 |
|
18 | | -Take a look at https://github.com/Yukaii/dotfiles/commit/569b50824c19340cefb308f385168492418f98e7 |
| 105 | +MIT |
0 commit comments