LocalDNS.wtf

Services

Managing local system services with LocalDNS - databases, caches, queues, and more.

Local System Services

LocalDNS supports managing local system services (databases, caches, queues, etc.) with always-on and lazy-loading capabilities.

Quick Start

# Add a database service (always-on)
localdns add postgres.local \
  --cmd "postgres -D /usr/local/var/postgres" \
  --startup always \
  --service-type database \
  --restart always

# Add a cache service (lazy-loaded)
localdns add redis.local \
  --cmd "redis-server" \
  --startup lazy \
  --service-type cache

# Add an API that depends on database
localdns add api.local \
  --cmd "npm start" \
  --startup lazy \
  --service-type api \
  --depends postgres.local

Startup Policies

always - Always-On Services

Services that start automatically when the daemon starts. Perfect for databases, caches, message queues, and background workers.

localdns service set postgres.local always

lazy - Lazy-Loaded Services

Services that start on first access, then stay running. Perfect for APIs, applications, and services you don't always use.

localdns service set api.local lazy

manual - Manual Start (Default)

Services that only start when explicitly started. Perfect for development apps, one-off scripts, and testing environments.

Restart Policies

PolicyBehavior
alwaysAutomatically restart if the service stops for any reason
on-failureOnly restart if the service exits with an error
neverDon't automatically restart (default)
localdns service restart-policy postgres.local always
localdns service restart-policy api.local on-failure

Service Types

Categorize services for better management:

TypeUse Case
appApplication (Next.js, React, etc.)
apiAPI server
databaseDatabase (PostgreSQL, MySQL, MongoDB)
cacheCache (Redis, Memcached)
queueMessage queue (RabbitMQ, Bull)
workerBackground worker
proxyProxy service
monitoringMonitoring/logging service
localdns service type postgres.local database

Dependencies

Define dependencies so services start in the correct order:

localdns service depends api.local postgres.local redis.local

When starting api.local, LocalDNS will check if dependencies are running, start them if needed, then start the API.

Health Checks

Configure health checks for services:

localdns service health api.local http://localhost:3000/health

Full Stack Example

# Database (always-on)
localdns add postgres.local \
  --cmd "postgres -D /usr/local/var/postgres" \
  --startup always --service-type database --restart always

# Cache (always-on)
localdns add redis.local \
  --cmd "redis-server" \
  --startup always --service-type cache --restart always

# API (lazy, depends on database and cache)
localdns add api.local \
  --cmd "cd apps/api && npm start" \
  --startup lazy --service-type api
localdns service depends api.local postgres.local redis.local

# Frontend (lazy, depends on API)
localdns add app.local \
  --cmd "cd apps/web && npm start" \
  --startup lazy --service-type app
localdns service depends app.local api.local

Best Practices

  • Use always for infrastructure services (databases, caches)
  • Use lazy for applications that depend on infrastructure
  • Use manual for development/testing apps
  • Set restart always for critical services
  • Define dependencies to ensure correct startup order
  • Use health checks for production-like services