Bun Process Manager
A Bun-native process manager inspired by PM2 that leverages Bun's built-in tools and APIs to provide fast, efficient process management for Node.js and Bun applications.
Features
- 🚀 Bun-Native: Built specifically for Bun runtime with optimized performance
- 🔄 Auto-Restart: Automatic process restart on crashes with configurable policies
- 📊 Monitoring: Real-time CPU and memory monitoring with resource limits
- 📝 Log Management: Automatic log capture, rotation, and streaming
- 🔧 Clustering: Multi-instance support for load balancing
- ⚙️ Configuration: Ecosystem files for complex multi-service setups
- 🛡️ Error Handling: Robust error recovery and graceful shutdowns
- 💾 Persistence: Process configurations survive daemon restarts
Installation
From Source
git clone https://github.com/eyuael/BunPM.git
cd bunpm
bun install
bun run build
Global Installation
bun install -g bunpm
Quick Start
bun-pm start server.js --name "my-app"
bun-pm list
bun-pm logs my-app --follow
bun-pm scale my-app 4
bun-pm stop my-app
Usage
Basic Commands
Starting Processes
bun-pm start app.js
bun-pm start app.js --name "web-server"
bun-pm start app.js --name "api" --env NODE_ENV=production
bun-pm start app.js --name "cluster-app" --instances 4
bun-pm start app.js --name "one-shot" --no-autorestart
bun-pm start app.js --name "limited" --memory 512M
Process Management
bun-pm list
bun-pm show my-app
bun-pm stop my-app
bun-pm restart my-app
bun-pm delete my-app
bun-pm scale my-app 8
Log Management
bun-pm logs my-app
bun-pm logs my-app --lines 50
bun-pm logs my-app --follow
bun-pm logs my-app --error
Monitoring
bun-pm monit
bun-pm show my-app
Configuration Management
bun-pm save ecosystem.json
bun-pm start ecosystem.json
bun-pm reload ecosystem.json
Advanced Usage
Clustering with Load Balancing
bun-pm start server.js --name "web" --instances 4
Memory Management
bun-pm start memory-intensive.js --memory 1G
bun-pm monit
Working Directory and Environment
bun-pm start ../other-project/app.js --cwd /path/to/project
bun-pm start app.js --env "NODE_ENV=production,API_KEY=secret"
Ecosystem Configuration
Create an ecosystem.json file to manage multiple processes:
{
"apps": [
{
"name": "web-server",
"script": "server.js",
"instances": 4,
"autorestart": true,
"memory": "512M",
"env": {
"NODE_ENV": "production",
"PORT": 3000
}
},
{
"name": "worker",
"script": "worker.js",
"instances": 2,
"cwd": "./workers",
"env": {
"WORKER_TYPE": "background"
}
},
{
"name": "scheduler",
"script": "scheduler.js",
"autorestart": true,
"memory": "256M",
"env": {
"SCHEDULE_INTERVAL": "60000"
}
}
]
}
Start all processes:
bun-pm start ecosystem.json
Example Configurations
The examples/ directory contains ready-to-use ecosystem configurations:
See the examples documentation for detailed explanations and best practices.
Bun-Specific Features
Performance Optimizations
- Fast Startup: Leverages Bun's quick cold start for minimal daemon initialization time
- Native APIs: Uses
Bun.spawn(), Bun.file(), and Bun.serve() for optimal performance
- Efficient JSON: Utilizes Bun's optimized JSON parsing for configuration handling
- Stream Processing: Native Bun streams for efficient log processing
Memory Efficiency
- Low Overhead: Daemon typically uses <50MB of memory
- Efficient Spawning: Minimal process creation overhead with
Bun.spawn()
- Smart Log Streaming: Prevents memory buildup during log operations
Integration Benefits
- Native File Operations: Fast configuration and log file handling
- Built-in HTTP: Health checks and monitoring using Bun's HTTP client
- TypeScript Support: Full TypeScript support without additional compilation
API Reference
Command Line Interface
start <script> | Start a new process | --name, --instances, --memory, --env, --cwd, --no-autorestart |
stop <name|id> | Stop a process | None |
restart <name|id> | Restart a process | None |
delete <name|id> | Delete process configuration | --force |
list | List all processes | --json |
show <name|id> | Show detailed process info | --json |
logs <name|id> | View process logs | --lines, --follow, --error |
scale <name|id> <instances> | Scale process instances | None |
monit | Real-time monitoring | None |
save [file] | Save ecosystem configuration | None |
reload <file> | Reload from ecosystem file | None |
Process Status Values
running: Process is active and healthy
stopped: Process has been manually stopped
errored: Process failed to start or crashed too many times
restarting: Process is being restarted
Development
Setup
git clone https://github.com/eyuael/BunPM.git
cd bunpm
bun install
Running Tests
bun test
bun run test:unit
bun run test:integration
bun run test:performance
bun run test:e2e
bun run test:stress
bun run test:comprehensive
bun run benchmark
Building
bun run build
bun run clean
Development Mode
bun run dev start server.js --name test-app
Performance
Benchmarks
- Daemon Startup: <100ms cold start
- Process Creation: <50ms per process
- Command Response: <10ms average
- Memory Footprint: <50MB daemon overhead
- Concurrent Processes: Tested with 1000+ processes
Scalability
The process manager is designed to handle:
- 1000+ concurrent managed processes
- High-frequency log output (>1000 lines/second)
- Rapid process cycling and restarts
- Large ecosystem configurations (100+ apps)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
MIT License - see LICENSE file for details
Documentation
Troubleshooting
See TROUBLESHOOTING.md for common issues and solutions.