Skip to content
nglmercerPublic

About

process management with advanced features like clustering, load balancing, health checks, hot reload, and remote deployment. Built with TypeScript and Bun for maximum performance and developer experience.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

77 Commits

Folders and files

Repository files navigation

TSPM - TypeScript Process Manager

Stars License

A modern, feature-rich process manager for Node.js and Bun applications. TSPM is a PM2 alternative written entirely in TypeScript.

Overview

TSPM (TypeScript Process Manager) provides robust process management with advanced features like clustering, load balancing, health checks, hot reload, and remote deployment. Built with TypeScript and Bun for maximum performance and developer experience.

✨ Features

Core Features

Feature Description
Process Lifecycle Start, stop, restart, reload, and delete processes
Process Clustering Run multiple instances of your application
Load Balancing 7 strategies: round-robin, random, least-connections, least-cpu, least-memory, ip-hash, weighted
Auto-restart Exponential backoff with configurable restart policies
Log Management File logging with rotation and structured JSON output
Hot Reload File watching with automatic process restart

Advanced Features

Feature Description
Health Checks HTTP, HTTPS, TCP, and command-based probes
Webhooks Event notifications for process lifecycle events
Source Maps Transparent stack trace support
Environment Variables .env file support with per-process configuration
Lifecycle Hooks preStart and postStart script execution
Real-time Monitoring Interactive dashboard with CPU and memory stats

Production Features

Feature Description
Startup Scripts Generate systemd/launchd scripts for boot persistence
Save/Resurrect Persist and restore process lists
Remote Deployment SSH-based deployment with pre/post hooks
Multi-environment Staging, production, and custom environments
Resource Limits Memory limits with OOM detection

πŸš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/nglmercer/tspm.git
cd tspm

# Install dependencies
bun install

Start Your First Process

# Start from a config file
bun src/cli/index.ts start -c tspm.yaml

# Or use the example configuration
bun src/cli/index.ts start -c examples/config/app.basic.yaml

Rust Crash & Respawn Test

Demonstrate process resilience and restart limits using a Rust application:

bun run example:rust

This example compiles a simple Rust HTTP server, starts it, crashes it repeatedly, and verifies that TSPM stops restarting it after maxRestarts is reached.

Basic Commands

# List all processes
bun src/cli/index.ts list

# View process logs
bun src/cli/index.ts logs

# Monitor processes in real-time
bun src/cli/index.ts monit

# Stop all processes
bun src/cli/index.ts stop --all

πŸ“‹ Configuration

Create a tspm.yaml or tspm.json file in your project:

# tspm.yaml
processes:
  - name: my-api
    script: bun
    args: [run, src/index.ts]
    instances: 2
    cwd: ./apps/api

    # Load balancing strategy
    lbStrategy: round-robin

    # Health checks
    healthCheck:
      enabled: true
      protocol: http
      path: /health
      interval: 30000
      retries: 3

    # Environment variables
    env:
      NODE_ENV: production
      PORT: "3000"

    # Resource limits
    maxMemory: 500M
    maxRestarts: 10

    # Lifecycle hooks
    preStart: echo "Starting..."
    postStart: curl -X POST https://webhooks.example.com/started

πŸ“– CLI Commands Reference

Process Management

Command Alias Description
start <config> start -c <file> Start processes from config file
stop [name] stop --all Stop running processes
restart [name] restart --all Restart processes
reload - Reload processes without downtime
delete [name] delete --all Remove processes from list
list ls List all processes (PM2-style)

Monitoring & Logs

Command Description
logs [name] [--lines N] View process logs
monit Real-time monitoring dashboard
describe <name> Show detailed process information
prettylist Pretty-printed JSON process list
report Generate diagnostic report

Clustering & Scaling

Command Description
cluster [name] Show cluster information
scale <name> <count> Scale cluster instances
groups Show process groups and namespaces

Development

Command Description
dev <config> Development mode with hot reload
serve <path> [port] Static file server

Deployment & Operations

Command Description
deploy [env] Deploy to remote server via SSH
save Save current process list
resurrect Restore saved processes
startup [platform] Generate systemd startup scripts
unstartup Remove startup scripts
flush Clear all log files
reset [name] Reset restart counters

πŸ“š Documentation

Document Description
πŸ“– Main README This file - overview and quick start
πŸš€ Deployment Guide Remote deployment via SSH with hooks
πŸ”§ Startup Guide System startup scripts and persistence
πŸ“Š Progress Report Implementation status and features
πŸ—ΊοΈ Roadmap Future development plans
βš™οΈ Configuration Reference Complete configuration options
πŸ’» CLI Reference Detailed CLI command reference

πŸ—οΈ Project Structure

TSPM/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ cli/                    # CLI implementation
β”‚   β”‚   β”œβ”€β”€ index.ts           # Entry point
β”‚   β”‚   β”œβ”€β”€ program.ts         # Command setup
β”‚   β”‚   β”œβ”€β”€ commands/          # Individual commands
β”‚   β”‚   β”‚   β”œβ”€β”€ start.ts       # Start command
β”‚   β”‚   β”‚   β”œβ”€β”€ stop.ts        # Stop command
β”‚   β”‚   β”‚   β”œβ”€β”€ list.ts        # List command
β”‚   β”‚   β”‚   β”œβ”€β”€ logs.ts        # Logs command
β”‚   β”‚   β”‚   β”œβ”€β”€ monit.ts       # Monit command
β”‚   β”‚   β”‚   β”œβ”€β”€ deploy.ts      # Deploy command
β”‚   β”‚   β”‚   └── ...            # More commands
β”‚   β”‚   β”œβ”€β”€ state/             # State management
β”‚   β”‚   └── ui/                # UI components
β”‚   β”œβ”€β”€ core/                   # Core functionality
β”‚   β”‚   β”œβ”€β”€ ManagedProcess.ts  # Process management
β”‚   β”‚   β”œβ”€β”€ ProcessManager.ts  # Multi-process manager
β”‚   β”‚   β”œβ”€β”€ ClusterManager.ts  # Clustering logic
β”‚   β”‚   β”œβ”€β”€ ConfigLoader.ts    # Config parsing
β”‚   β”‚   └── types.ts           # Type definitions
β”‚   └── utils/                  # Utilities
β”‚       β”œβ”€β”€ monitoring.ts      # Process monitoring
β”‚       β”œβ”€β”€ logger.ts          # Logging utilities
β”‚       β”œβ”€β”€ webhooks.ts        # Webhook support
β”‚       β”œβ”€β”€ healthcheck/       # Health check system
β”‚       β”œβ”€β”€ loadbalancer/      # Load balancing
β”‚       └── events/            # Event system
β”œβ”€β”€ tests/                      # Test suite
β”œβ”€β”€ examples/                   # Example configs and apps
β”‚   β”œβ”€β”€ config/                # Configuration examples
β”‚   └── applications/          # Example applications
β”œβ”€β”€ docs/                       # Documentation
└── tspm.yaml                   # Example config

πŸ“Š PM2 Feature Comparison

Feature PM2 TSPM Notes
Process management βœ… βœ… Full lifecycle support
Clustering βœ… βœ… Multiple instances
Load balancing βœ… βœ… 7 strategies
Health checks βœ… βœ… HTTP/TCP/Command
Log management βœ… βœ… File + rotation
Hot reload βœ… βœ… File watcher
Environment vars βœ… βœ… .env support
Source maps βœ… βœ… Stack trace support
Webhooks βœ… βœ… Event notifications
Startup scripts βœ… βœ… systemd/launchd
Save/Resurrect βœ… βœ… Process persistence
Deployment βœ… βœ… SSH deploy
Static serve βœ… βœ… File server
Diagnostic report βœ… βœ… Full diagnostics

πŸ§ͺ Testing

# Run all tests
bun test

# Run specific test file
bun test tests/core/ManagedProcess.test.ts

# Run with coverage
bun test --coverage

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

MIT License - see the LICENSE file for details.


About

process management with advanced features like clustering, load balancing, health checks, hot reload, and remote deployment. Built with TypeScript and Bun for maximum performance and developer experience.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages