Skip to content

Configuration Templates ​

Use Tera templates in configuration fields to reference values from other daemons, settings, and runtime state.

Why Templates? ​

When daemons depend on each other, you often need to pass connection details between them. Without templates, you have to hardcode ports and URLs:

toml
[daemons.redis]
run = "redis-server --port $PORT"
port = 6379

[daemons.api]
run = "server --port 3000 --redis-port 6379"  # hardcoded!
env = { DATABASE_URL = "redis://localhost:6379/0" }  # hardcoded!
depends = ["redis"]

This breaks when redis uses port = { expect = [6379], bump = 10 } and the port gets auto-bumped. Templates solve this by resolving values at start time.

Basic Usage ​

The supported fields listed below can use {{ ... }} template expressions:

toml
[daemons.redis]
run = "redis-server --port $PORT"
port = 6379

[daemons.api]
run = "server --redis-port {{ daemons.redis.port }}"
env = { DATABASE_URL = "redis://localhost:{{ daemons.redis.port }}/0" }
depends = ["redis"]

Template rendering follows the dependency order: daemons in later levels can reference values from daemons that completed successfully in earlier levels. If a daemon has depends = ["redis"], it starts after redis and can use {{ daemons.redis.port }}.

Daemons the supervisor starts on its own are rendered the same way. boot_start daemons start in depends order at boot. A cron daemon that only its schedule has started is rendered again from its config for every scheduled run, so it picks up the current ports of the daemons it names. Once you start it yourself, its scheduled runs reuse the options of that start.

Template Fields ​

Templates work in these configuration fields:

FieldExample
runrun = "server --port {{ daemons.redis.port }}"
env valuesenv = { DB_URL = "postgres://localhost:{{ daemons.db.port }}" }
hooks.* commandson_ready = "echo {{ id }} is ready"
ready_cmdready_cmd = "redis-cli -p {{ daemons.redis.port }} ping"
ready_httpready_http = "http://localhost:{{ daemons.backend.port }}/health"
ready_portready_port = "{{ daemons.redis.port }}" (must render to a port number)
ready_outputready_output = "listening on port {{ daemons.api.port }}"

Health check fields (health_cmd, health_http, and health_port) also accept templates. These examples reference dependencies; use $PORT in commands for the current daemon's own assigned port, which can differ from its configured {{ port }} after a bump.

Template Variables ​

Self Variables ​

The current daemon's own metadata is always available:

VariableDescriptionExample
{{ name }}Daemon short name"api"
{{ namespace }}Daemon namespace"myproj"
{{ id }}Qualified ID"myproj/api"
{{ slug }}Legacy proxy slug alias (or null)"myapi"
{{ host }}Proxy hostname without the TLD (or null)"api.myproj"
{{ url }}Full proxy URL, else the daemon's declared url (or null)"https://api.myproj.localhost"
{{ port }}First configured port (or null)3000
{{ ports }}All configured ports[3000, 3001]
{{ dir }}Resolved working directory"/home/user/myproj"
{{ instance }}Daemon template instance name (or null)"1"
{{ instance_index }}Daemon template instance position (or null)1

Daemon References ​

Reference same-namespace daemons by their short name:

VariableDescriptionExample
{{ daemons.redis.port }}First resolved port6379
{{ daemons.redis.ports }}All resolved ports[6379, 6380]
{{ daemons.redis.ports[0] }}Port by index6379
{{ daemons.redis.id }}Qualified ID"myproj/redis"
{{ daemons.redis.name }}Short name"redis"
{{ daemons.redis.namespace }}Namespace"myproj"
{{ daemons.redis.slug }}Legacy slug alias"myredis"
{{ daemons.redis.host }}Proxy hostname without the TLD"redis.myproj"
{{ daemons.redis.url }}Full proxy URL, else its declared url"https://redis.myproj.localhost"
{{ daemons.redis.dir }}Working directory"/home/user/myproj"

TIP

port is shorthand for ports[0]. Use ports[N] when a daemon has multiple ports configured.

Environment values ​

Top-level [env] values apply to all daemons; per-daemon values override them. After the environment is rendered, commands and probes can reference it:

toml
[env]
APP_ENV = "development"

[daemons.worker]
run = "./worker --environment {{ env.APP_ENV }}"

Environment values are rendered independently, so do not use one environment template to depend on another environment template's result.

Cross-Namespace References ​

When referencing daemons in a different namespace, use the namespace.name key format in templates and namespace/name in depends. For example, if the registered infra namespace defines a redis daemon with a configured port:

toml
[daemons.api]
run = "node server.js"
env = { REDIS_URL = 'redis://localhost:{{ daemons["infra.redis"].port }}' }
depends = ["infra/redis"]

Here, server.js must read REDIS_URL from its environment. See the namespace registry to make the infra project available from other directories.

Naming a dependency ​

A qualified key such as daemons["infra.redis"] is awkward when the namespace is generated or changes between checkouts. Give the dependency a local name with as in depends, and use that name in templates:

toml
[daemons.app]
run = "node server.js"
depends = [{ id = "search-bd9126f3bbca47d/app", as = "search" }]

[daemons.app.env]
SEARCH_API_URL = "{{ daemons.search.url }}"

The dependency stays available under its qualified key too. Plain string entries in depends work as before. An as name may use letters, digits, _ and -, and config parsing fails if it matches a daemon in the same namespace or names two different dependencies. Pointing id at another checkout of the dependency then changes nothing else in the config.

Settings ​

Global proxy settings are available:

VariableDescription
{{ settings.proxy.enable }}Whether the proxy is enabled
{{ settings.proxy.tld }}Proxy TLD (default: "localhost")
{{ settings.proxy.port }}Proxy port (default: 443)
{{ settings.proxy.https }}Whether HTTPS is enabled

Proxy URL ​

{{ url }} provides the current daemon's full proxy URL. Use {{ daemons.api.url }} to reference the URL of an api dependency. The URL uses a registered slug when available, otherwise the automatic hostname.

For a registered project named myproj, with HTTPS enabled on port 443:

toml
[daemons.api]
run = "node server.js"
port = 3000
env.PUBLIC_URL = "{{ url }}"
# PUBLIC_URL: https://api.myproj.localhost

[daemons.worker]
depends = ["api"]
run = "./worker --api {{ daemons.api.url }}"
# Renders to: ./worker --api https://api.myproj.localhost

The proxy URL is null when the proxy is disabled or no routable hostname is available; {{ url }} then falls back to a declared url if the daemon has one and it renders, and is null otherwise. Automatic hostnames require a port and are disabled by proxy = false; existing slug mappings still apply. Label conflicts can also prevent an automatic hostname from being assigned.

The daemon receives the proxy URL as PITCHFORK_URL in its environment; it matches {{ proxy_url }}, not a declared url. {{ host }} contains the hostname without the TLD, such as api.myproj. {{ proxy_url }} is the proxy URL alone: it stays null for a daemon the proxy doesn't serve, even when the daemon declares a url.

Declared URL ​

When the proxy doesn't serve a daemon (proxy = false, the proxy is off, the daemon sets no port, or no hostname can be derived for it), there is no proxy URL. With the proxy enabled, a legacy slug mapping is the exception: it still gives the daemon a proxy URL, which wins over the declared one. A daemon can declare the URL it answers on with url, so consumers don't have to guess the scheme and host from the port. {{ url }} then uses the declared url, and is null only when the daemon declares none or it fails to render. The proxy doesn't check a daemon's protocol, so a non-HTTP daemon with a port must set proxy = false to get its declared URL:

toml
[daemons.cache]
run = "redis-server --port $PORT"
port = 6380
proxy = false
url = "redis://127.0.0.1:{{ port }}/0"

[daemons.web]
depends = ["cache"]
run = "./web"
env.REDIS_URL = "{{ daemons.cache.url }}"
# REDIS_URL: redis://127.0.0.1:6380/0

The declared url is a template. In it, {{ port }} and {{ ports }} are the daemon's own ports. When another daemon reads {{ daemons.cache.url }}, they are the ports the daemon actually got, including a bump, so the URL follows the port. The daemon's own {{ url }} is built from its configured ports, so it can be stale after a bump. The proxy URL wins whenever there is one, because it's stable across checkouts. To always get the direct address, set proxy = false and remove any legacy slug mapping for the daemon, since a slug still gets a proxy URL. A daemon without url behaves as before.

TIP

Elsewhere in a daemon's own config, {{ port }} is the port it is configured for. If port bumping moves it, $PORT in the command has the port it actually got.

Resolution Order ​

Templates are rendered level-by-level following the dependency graph:

Level 0: redis    (no dependencies, starts first)
Level 1: api      (depends on redis, templates can reference redis)
Level 2: worker   (depends on api, templates can reference redis and api)
  • Daemons within the same level start concurrently and cannot reference each other's ports
  • A daemon can reference any daemon that completed successfully in a previous level
  • {{ port }} and {{ ports }} for the current daemon are the ports it is configured for. The final ports are resolved after the command is constructed, so a bumped port can differ. Use the $PORT / $PORT0, $PORT1, ... environment variables to access the current daemon's own resolved ports. {{ daemons.xxx.port }} for a dependency is its resolved port

Error Handling ​

  • Undefined template variables produce clear errors at start time (strict mode)
  • A template error in run or env prevents the daemon from starting, and its dependents are also skipped
  • A template error in a hook command logs a warning and skips the hook execution

Examples ​

Database Connection String ​

toml
[daemons.postgres]
run = "postgres -D /usr/local/var/postgres"
port = 5432

[daemons.api]
run = "node server.js"
env = { DATABASE_URL = "postgres://localhost:{{ daemons.postgres.port }}/myapp" }
depends = ["postgres"]

Multiple Services ​

toml
[daemons.redis]
run = "redis-server --port $PORT"
port = 6379

[daemons.postgres]
run = "postgres"
port = 5432

[daemons.api]
run = "server start"
env = { REDIS_URL = "redis://localhost:{{ daemons.redis.port }}", DATABASE_URL = "postgres://localhost:{{ daemons.postgres.port }}/app" }
depends = ["redis", "postgres"]

Multiple Ports ​

toml
[daemons.grpc]
run = "grpc-server"
port = [50051, 50052]

[daemons.gateway]
run = "gateway --grpc-port {{ daemons.grpc.ports[0] }} --metrics-port {{ daemons.grpc.ports[1] }}"
depends = ["grpc"]

Auto-Bumped Port ​

When bump is configured, the resolved port may differ from the expected port. Templates always use the resolved value:

toml
[daemons.redis]
run = "redis-server --port $PORT"
port = { expect = [6379], bump = 10 }
# If 6379 is occupied, redis starts on 6380 or another available port within the attempt limit

[daemons.api]
run = "server --redis-port {{ daemons.redis.port }}"
# Always uses the actual port, regardless of bumping
depends = ["redis"]

Hook with Port Reference ​

toml
[daemons.api]
run = "node server.js"
port = 3000
ready_http = "http://localhost:3000/health"

[daemons.monitor]
run = "echo monitoring"
depends = ["api"]

[daemons.monitor.hooks]
on_ready = "curl -X POST https://monitor.example.com/register -d '{\"url\": \"http://localhost:{{ daemons.api.port }}\"}'"
MIT LicenseCopyright © 2026jdx.dev