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.localStartup 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 alwayslazy - 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 lazymanual - Manual Start (Default)
Services that only start when explicitly started. Perfect for development apps, one-off scripts, and testing environments.
Restart Policies
| Policy | Behavior |
|---|---|
always | Automatically restart if the service stops for any reason |
on-failure | Only restart if the service exits with an error |
never | Don't automatically restart (default) |
localdns service restart-policy postgres.local always
localdns service restart-policy api.local on-failureService Types
Categorize services for better management:
| Type | Use Case |
|---|---|
app | Application (Next.js, React, etc.) |
api | API server |
database | Database (PostgreSQL, MySQL, MongoDB) |
cache | Cache (Redis, Memcached) |
queue | Message queue (RabbitMQ, Bull) |
worker | Background worker |
proxy | Proxy service |
monitoring | Monitoring/logging service |
localdns service type postgres.local databaseDependencies
Define dependencies so services start in the correct order:
localdns service depends api.local postgres.local redis.localWhen 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/healthFull 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.localBest Practices
- Use
alwaysfor infrastructure services (databases, caches) - Use
lazyfor applications that depend on infrastructure - Use
manualfor development/testing apps - Set
restart alwaysfor critical services - Define dependencies to ensure correct startup order
- Use health checks for production-like services