Services
Services are long-running processes managed by the Sprite runtime that automatically restart when your Sprite boots. Unlike detachable sessions, services survive full Sprite restarts and are ideal for background daemons, development servers, and databases.
Overview
Section titled “Overview”Services are managed through the internal API at /.sprite/api.sock. The sprite-env command provides a convenient wrapper:
# List all servicessprite-env services list
# Get help and see all endpointssprite-env services --helpCreating Services
Section titled “Creating Services”Create a service with a PUT request:
# Simple servicesprite-env curl -X PUT /v1/services/myapp -d '{ "cmd": "/usr/bin/myapp", "args": ["--port", "8080"]}'
# Service with dependenciessprite-env curl -X PUT /v1/services/webapp -d '{ "cmd": "npm", "args": ["run", "dev"], "needs": ["database"]}'Service Configuration
Section titled “Service Configuration”| Field | Type | Description |
|---|---|---|
cmd | string | Path to executable (required) |
args | string[] | Command arguments |
needs | string[] | Services that must start first |
Streaming Logs on Creation
Section titled “Streaming Logs on Creation”When you create a service, the API streams logs in NDJSON format:
# Stream logs for 10 seconds after creationsprite-env curl -X PUT '/v1/services/myapp?duration=10s' -d '{ "cmd": "npm", "args": ["run", "dev"]}'The default streaming duration is 5 seconds. Set duration=0 to return immediately without streaming.
Managing Services
Section titled “Managing Services”List Services
Section titled “List Services”sprite-env services listReturns a JSON array of services with their current states:
[ { "name": "webapp", "cmd": "npm", "args": ["run", "dev"], "needs": [], "state": { "name": "webapp", "status": "running", "pid": 1234, "started_at": "2024-01-15T10:30:00Z" } }]Get Service State
Section titled “Get Service State”sprite-env services get webappDelete a Service
Section titled “Delete a Service”sprite-env services delete webappSend Signals
Section titled “Send Signals”Send Unix signals to a service:
# Graceful shutdownsprite-env curl -X POST /v1/services/signal -d '{ "name": "webapp", "signal": "TERM"}'
# Force killsprite-env curl -X POST /v1/services/signal -d '{ "name": "webapp", "signal": "KILL"}'
# Reload configuration (for services that support it)sprite-env curl -X POST /v1/services/signal -d '{ "name": "nginx", "signal": "HUP"}'Services vs Detachable Sessions
Section titled “Services vs Detachable Sessions”Choose the right approach for your use case:
| Feature | Services | Detachable Sessions |
|---|---|---|
| Survives Sprite restart | Yes | No |
| Auto-starts on boot | Yes | No |
| Managed via | Internal API | External CLI/SDK |
| Dependencies | Supported (needs) | Not supported |
| Best for | Daemons, servers | One-off tasks, builds |
When to Use Services
Section titled “When to Use Services”- Development servers that should always be running
- Databases like PostgreSQL, Redis, or SQLite servers
- Background workers processing queues
- Reverse proxies or other infrastructure
When to Use Detachable Sessions
Section titled “When to Use Detachable Sessions”- Build processes that run once
- Long-running scripts you want to monitor
- Interactive sessions you might reconnect to
Common Patterns
Section titled “Common Patterns”Development Server
Section titled “Development Server”# Create a Node.js dev server servicesprite-env curl -X PUT /v1/services/devserver -d '{ "cmd": "npm", "args": ["run", "dev"]}'Database with Dependent Service
Section titled “Database with Dependent Service”# First, create the database servicesprite-env curl -X PUT /v1/services/postgres -d '{ "cmd": "/usr/lib/postgresql/16/bin/postgres", "args": ["-D", "/home/sprite/pgdata"]}'
# Then create a service that depends on itsprite-env curl -X PUT /v1/services/webapp -d '{ "cmd": "npm", "args": ["start"], "needs": ["postgres"]}'Python Background Worker
Section titled “Python Background Worker”sprite-env curl -X PUT /v1/services/worker -d '{ "cmd": "python", "args": ["-m", "celery", "worker", "-A", "tasks"]}'LLM Integration
Section titled “LLM Integration”AI coding agents can manage services through the internal API. Point your LLM at /.sprite/llm.txt for environment documentation, then it can:
# LLM creates a service for the project it's working onsprite-env curl -X PUT /v1/services/devserver -d '{ "cmd": "npm", "args": ["run", "dev"], "dir": "/home/sprite/project"}'
# Check if it's runningsprite-env services get devserver
# Restart after making changessprite-env curl -X POST /v1/services/signal -d '{"name": "devserver", "signal": "TERM"}'# Service auto-restartsTroubleshooting
Section titled “Troubleshooting”Service Won’t Start
Section titled “Service Won’t Start”- Check the command path is correct and executable exists
- Verify working directory exists
- Check dependencies are running if using
needs
Service Keeps Restarting
Section titled “Service Keeps Restarting”The service manager will restart crashed services. If a service exits immediately:
- Check logs during creation with
duration=30s - Verify environment variables are set correctly
- Test the command manually first
Viewing Service Logs
Section titled “Viewing Service Logs”Stream logs when creating the service:
sprite-env curl -X PUT '/v1/services/myapp?duration=60s' -d '{...}'Or check system logs:
journalctl -f # If available# ortail -f /var/log/syslog