https://github.com/nxht/bun-cluster-reload
PM2-like cluster with reload for bun
https://github.com/nxht/bun-cluster-reload
bun
Last synced: 4 months ago
JSON representation
PM2-like cluster with reload for bun
- Host: GitHub
- URL: https://github.com/nxht/bun-cluster-reload
- Owner: nxht
- Created: 2024-03-10T05:23:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-06T07:34:39.000Z (about 2 years ago)
- Last Synced: 2025-10-31T03:43:27.674Z (8 months ago)
- Topics: bun
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/bun-cluster-reload
- Size: 47.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# bun-cluster-reload
pm2-like cluster with reload for bun
## Installation
```bash
bun add bun-cluster-reload
```
## Features
- Auto-restart on error
- [PM2-like reload](https://pm2.keymetrics.io/docs/usage/cluster-mode/#reload) on signal
- [PM2-like waitReady](https://pm2.keymetrics.io/docs/usage/signals-clean-restart/#graceful-start) option
## Example
```typescript
import { ClusterRunner } from 'bun-cluster-reload';
const clusterRunner = new ClusterRunner({
numCPUs: 2,
logger: console,
autorestart: true,
waitReady: true,
});
await clusterRunner.start({
command: ['bun', 'src/index.ts'],
reloadSignal: 'SIGHUP',
updateEnv: false,
});
```
### Using with PM2
- Set `bun` as pm2 interpreter as in [official Bun guide](https://bun.sh/guides/ecosystem/pm2)
- The target script should be the ClusterRunner file
- Note that the clustering happens in `bun` not `pm2`. So you'll see a single process in pm2 monitoring
- To reload, send predefined signal to process using `pm2 send signal`. For example:
```bash
pm2 sendSignal SIGHUP app
```