Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nxht/bun-cluster-reload
PM2-like cluster with reload for bun
https://github.com/nxht/bun-cluster-reload
bun
Last synced: 22 days 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 (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-06T07:34:39.000Z (5 months ago)
- Last Synced: 2024-10-06T15:33:20.646Z (about 1 month ago)
- Topics: bun
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/bun-cluster-reload
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.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
```