Services and the Sprite lifecycle
What happens to a service depends on how the Sprite went down and how it came back:- Warm wake. The VM was suspended with your process inside it. The process resumes mid-thought; it is not restarted. Wakes take 100–500ms.
- Cold boot. Process state was dropped. The runtime starts every service fresh, in dependency order. Wakes take 1–2s.
- Crash. A service process that exits on its own gets restarted by the runtime.
- Stop. A service you stop explicitly stays stopped until you start it again.
Create a service
Thesprite-env CLI ships in every Sprite and talks to the runtime’s management socket. Create a service with a name, a command, and its arguments:
--cmd takes the binary only. Arguments go in --args, comma-separated.
The command starts the service and streams its first few seconds of output as NDJSON, so a service that dies on startup fails in front of you instead of silently in the background:
--duration 30s to watch longer, or --no-stream to return immediately.
Confirm it’s serving:
Create options
Serving HTTP
Every Sprite has a URL, and the Sprite’s proxy routes incoming requests to port 8080 by default. A service created with--http-port changes that:
- Requests to the Sprite’s URL route to the service’s port instead of 8080.
- If the service isn’t running when a request arrives, the proxy starts it first, then forwards the request.
- Only one service can have an HTTP port. Creating a second one fails with
409: another service already has an HTTP port configured.
Managing services
get returns the definition plus live state:
stopis sticky. A stopped service stays stopped. The runtime won’t restart it behind your back.- Killing the process is not. Send
TERMorKILLviasignal, or kill the PID directly, and the runtime treats it as a crash and restarts the service. The state’srestart_countincrements each time. This meanssignal web TERMis effectively a restart; for clarity, userestartinstead. deleteremoves the definition, not the logs. The log file stays in/.sprite/logs/services/after the service is gone.
Logs
Everything a service writes to stdout or stderr lands in/.sprite/logs/services/<name>.log, timestamped and tagged with the stream it came from:
--duration on create, start, or restart.
There is no journalctl here. Sprites don’t run systemd; the log files and the create/start streams are how you see service output.
Dependencies
A service with--needs starts after the services it names. Use it when one process can’t come up until another is ready:
postgres before app, every time.
Services, sessions, or tasks?
There are three ways to run something in a Sprite, and they solve different problems:
They compose. A common pattern for background agents: a service launches the agent at boot, the agent registers a task while it works, the task expires when the work is done, and the Sprite pauses until something needs it again. See Keeping a Sprite Running for the task side of that pattern.
Troubleshooting
The service died immediately. The create stream tells you, with anexit event:
--cmd path looks like this:
restart_count in sprite-env services get <name>. Read the log file to find out why it’s crashing, and test the command by hand in a shell with the same --dir and --env.
Requests to the Sprite’s URL aren’t reaching the service.
Check that the service actually has the HTTP port: sprite-env services list and look for http_port. Without it, the proxy routes to port 8080, not to your service.
Managing services from outside the Sprite
Everything on this page uses the in-Sprite CLI. The same operations are available from outside through the Sprites REST API at/v1/sprites/{name}/services and the SDKs, which is how you’d configure services as part of provisioning a fleet of Sprites. See the Services API reference for endpoints and request schemas.
Related documentation
Keeping a Sprite Running
Use the Tasks API to hold a Sprite open while work finishes
Working with Sprites
Lifecycle, networking, and URL authentication
CLI Commands
The full sprite CLI reference