Skip to main content

Configuration

PMDaemon provides flexible configuration options that allow you to customize every aspect of process management. From basic process settings to advanced clustering and health checks, PMDaemon's configuration system is designed for both simplicity and power.

Overview

PMDaemon supports configuration through:

  • 🖥️ CLI arguments - Direct command-line configuration
  • 📄 Configuration files - JSON, YAML, and TOML formats
  • 🔧 Environment variables - System-level configuration
  • ⚙️ Runtime overrides - Temporary configuration changes
  • 🎯 Default values - Sensible defaults for all options

Configuration Methods

1. CLI Arguments (Primary)

The most common way to configure processes:

pmdaemon start "node server.js" \
--name web-api \
--instances 2 \
--port 3000-3001 \
--max-memory 512M \
--env NODE_ENV=production \
--health-check-url http://localhost:3000/health \
--wait-ready

2. Configuration Files

Define complex configurations in files:

ecosystem.json:

{
"apps": [
{
"name": "web-api",
"script": "node",
"args": ["server.js"],
"instances": 2,
"port": "3000-3001",
"max_memory_restart": "512M",
"env": {
"NODE_ENV": "production"
},
"health_check": {
"check_type": "http",
"url": "http://localhost:3000/health",
"timeout": 5,
"interval": 30,
"retries": 3,
"enabled": true
}
}
]
}

ecosystem.yaml:

apps:
- name: web-api
script: node
args: [server.js]
instances: 2
port: "3000-3001"
max_memory_restart: 512M
env:
NODE_ENV: production
health_check:
check_type: http
url: http://localhost:3000/health
timeout: 5
interval: 30
retries: 3
enabled: true

3. Environment Variables

System-level configuration:

# Set default values
export PMDAEMON_DEFAULT_INSTANCES=2
export PMDAEMON_DEFAULT_MAX_MEMORY=512M
export PMDAEMON_LOG_LEVEL=info

# Use in commands
pmdaemon start "node server.js" --name web-api

Core Configuration Options

Basic Process Settings

OptionCLI FlagDefaultDescription
Name--nameRequiredUnique process identifier
ScriptFirst argumentRequiredCommand or script to execute
Arguments--args[]Command line arguments
Working Directory--cwdCurrent dirProcess working directory
Instances--instances1Number of process instances
# Basic configuration
pmdaemon start "python app.py" \
--name python-api \
--args "--port 8000 --workers 4" \
--cwd /app \
--instances 2

Environment Variables

OptionCLI FlagDefaultDescription
Environment--envInheritedEnvironment variables
Environment File--env-fileNoneLoad environment from file
# Set environment variables
pmdaemon start "node server.js" \
--name web-api \
--env NODE_ENV=production \
--env DATABASE_URL=postgres://localhost/mydb \
--env-file .env.production

Resource Limits

OptionCLI FlagDefaultDescription
Memory Limit--max-memoryUnlimitedMemory limit before restart
CPU Limit--max-cpuUnlimitedCPU limit (future feature)
# Set resource limits
pmdaemon start "node server.js" \
--name web-api \
--max-memory 1G

Memory format examples:

  • 100K or 100KB - Kilobytes
  • 512M or 512MB - Megabytes
  • 2G or 2GB - Gigabytes
  • 1073741824 - Raw bytes

Port Management

OptionCLI FlagDefaultDescription
Port--portNonePort assignment
Port Range--portNonePort range for clusters
Auto Port--portNoneAuto-assign from range
# Port configuration examples
pmdaemon start "node server.js" --port 3000 # Single port
pmdaemon start "node server.js" --instances 4 --port 3000-3003 # Port range
pmdaemon start "node server.js" --instances 3 --port auto:5000-5100 # Auto-assign

Process Control

OptionCLI FlagDefaultDescription
Auto Restart--autorestarttrueRestart on crash
Max Restarts--max-restarts16Maximum restart attempts
Min Uptime--min-uptime1000msMinimum uptime before stable
Restart Delay--restart-delay0msDelay between restarts
Kill Timeout--kill-timeout1600msGraceful shutdown timeout
# Process control configuration
pmdaemon start "node server.js" \
--name web-api \
--autorestart true \
--max-restarts 10 \
--min-uptime 5s \
--restart-delay 1s \
--kill-timeout 30s

Logging Configuration

OptionCLI FlagDefaultDescription
Output File--out-fileAuto-generatedStdout log file
Error File--error-fileAuto-generatedStderr log file
Log File--log-fileAuto-generatedCombined log file
PID File--pid-fileAuto-generatedProcess ID file
# Logging configuration
pmdaemon start "node server.js" \
--name web-api \
--out-file /var/log/web-api.out \
--error-file /var/log/web-api.err \
--pid-file /var/run/web-api.pid

Health Checks

OptionCLI FlagDefaultDescription
Health Check URL--health-check-urlNoneHTTP health check endpoint
Health Check Script--health-check-scriptNoneScript-based health check
Health Check Timeout--health-check-timeout30sHealth check timeout
Health Check Interval--health-check-interval60sHealth check frequency
Health Check Retries--health-check-retries3Retries before failure
Wait Ready--wait-readyfalseBlock start until healthy
Wait Timeout--wait-timeout30sBlocking start timeout
# Health check configuration
pmdaemon start "node api.js" \
--name api-service \
--port 3000 \
--health-check-url http://localhost:3000/health \
--health-check-timeout 10s \
--health-check-interval 30s \
--health-check-retries 5 \
--wait-ready \
--wait-timeout 60s

Advanced Configuration

Clustering Configuration

# Advanced clustering setup
pmdaemon start "node server.js" \
--name web-cluster \
--instances 4 \
--port 3000-3003 \
--exec-mode cluster \
--instance-var INSTANCE_ID \
--merge-logs true

Namespace Configuration

# Organize processes by namespace
pmdaemon start "node api.js" \
--name api \
--namespace production

pmdaemon start "node worker.js" \
--name worker \
--namespace production

# List processes by namespace
pmdaemon list --namespace production

Watch Mode (Future Feature)

# File watching for auto-restart
pmdaemon start "node server.js" \
--name dev-server \
--watch true \
--watch-delay 1000 \
--ignore-watch "node_modules logs *.log"

Configuration File Formats

JSON Configuration

{
"apps": [
{
"name": "web-api",
"script": "node",
"args": ["server.js"],
"instances": 2,
"port": "3000-3001",
"cwd": "/app",
"env": {
"NODE_ENV": "production",
"PORT": "3000"
},
"max_memory_restart": "512M",
"autorestart": true,
"max_restarts": 10,
"min_uptime": "5s",
"health_check": {
"check_type": "http",
"url": "http://localhost:3000/health",
"timeout": 10,
"interval": 30,
"retries": 3,
"enabled": true
},
"log": {
"out_file": "/var/log/web-api.out",
"error_file": "/var/log/web-api.err",
"pid_file": "/var/run/web-api.pid"
}
}
]
}

YAML Configuration

apps:
- name: web-api
script: node
args: [server.js]
instances: 2
port: "3000-3001"
cwd: /app
env:
NODE_ENV: production
PORT: "3000"
max_memory_restart: 512M
autorestart: true
max_restarts: 10
min_uptime: 5s
health_check:
check_type: http
url: http://localhost:3000/health
timeout: 10
interval: 30
retries: 3
enabled: true
log:
out_file: /var/log/web-api.out
error_file: /var/log/web-api.err
pid_file: /var/run/web-api.pid

TOML Configuration

[[apps]]
name = "web-api"
script = "node"
args = ["server.js"]
instances = 2
port = "3000-3001"
cwd = "/app"
max_memory_restart = "512M"
autorestart = true
max_restarts = 10
min_uptime = "5s"

[apps.env]
NODE_ENV = "production"
PORT = "3000"

[apps.health_check]
check_type = "http"
url = "http://localhost:3000/health"
timeout = 10
interval = 30
retries = 3
enabled = true

[apps.log]
out_file = "/var/log/web-api.out"
error_file = "/var/log/web-api.err"
pid_file = "/var/run/web-api.pid"

Configuration Validation

PMDaemon validates all configuration options:

Required Fields

# Error: Missing required fields
pmdaemon start --name web-api
# Error: Script is required

pmdaemon start "node server.js"
# Error: Name is required

Value Validation

# Error: Invalid memory format
pmdaemon start "node server.js" --name web-api --max-memory "invalid"
# Error: Invalid memory format 'invalid'. Use formats like '512M', '1G', etc.

# Error: Invalid port range
pmdaemon start "node server.js" --name web-api --instances 4 --port 3000-3001
# Error: Port range 3000-3001 has only 2 ports but 4 instances requested

Conflict Detection

# Error: Name conflict
pmdaemon start "node server.js" --name web-api
pmdaemon start "python app.py" --name web-api
# Error: Process with name 'web-api' already exists

# Error: Port conflict
pmdaemon start "node server.js" --name api1 --port 3000
pmdaemon start "python app.py" --name api2 --port 3000
# Error: Port 3000 is already assigned to process 'api1'

Configuration Best Practices

1. Use Configuration Files for Complex Setups

# Good: Use config file for multiple processes
pmdaemon --config ecosystem.json start

# Avoid: Long CLI commands
pmdaemon start "node server.js" --name web-api --instances 4 --port 3000-3003 --max-memory 512M --env NODE_ENV=production --health-check-url http://localhost:3000/health --wait-ready

2. Set Appropriate Resource Limits

# Good: Set memory limits
pmdaemon start "node server.js" --name web-api --max-memory 512M

# Avoid: No limits (can cause system issues)
pmdaemon start "node server.js" --name web-api

3. Use Health Checks for Critical Services

# Good: Health checks for web services
pmdaemon start "node api.js" \
--name api \
--health-check-url http://localhost:3000/health

# Good: Script checks for workers
pmdaemon start "python worker.py" \
--name worker \
--health-check-script ./health-check.sh

4. Organize with Namespaces

# Good: Use namespaces for organization
pmdaemon start "node api.js" --name api --namespace production
pmdaemon start "node worker.js" --name worker --namespace production

# List by namespace
pmdaemon list --namespace production

Runtime Configuration Changes

Temporary Overrides

# Start with default configuration
pmdaemon start "node server.js" --name web-api --port 3000

# Restart with temporary port override
pmdaemon restart web-api --port 3001

# Configuration file still shows port 3000, but process runs on 3001

Permanent Changes

# To permanently change configuration, delete and recreate
pmdaemon delete web-api
pmdaemon start "node server.js" --name web-api --port 3001

Next Steps