Configuration

# Autoscale

The cloud provider that holds the pool members of scaled roles: UpCloud, or your own scripts.

Where the pool members of scaled roles (see `scale` in dash docs role) live. dash asks the provider for them at the start of a command — the provider is the source of truth for which extra hosts are running, so there is no state file to drift.

## UpCloud

Members are UpCloud servers carrying the `dash.service`, `dash.destination` and `dash.role` labels. The API user's credentials are secrets: a one-element array names the secret to read, as for `registry/password`. They are sent to the UpCloud API as HTTP basic auth and nowhere else.

Set exactly one provider.

```yaml
autoscale:
  provider:
    upcloud:
      username:
        - UPCLOUD_USERNAME
      password:
        - UPCLOUD_PASSWORD
```

## Exec

Your own scripts, for any other cloud. Each runs locally with the role's labels as DASH_SERVICE, DASH_DESTINATION (`-` without a destination) and DASH_ROLE in its environment, plus DASH_MEMBER_ID and DASH_HOST for the member it acts on, and DASH_STOP_TIMEOUT (seconds) for `stop`. Only `members`, `start` and `stop` are required; `create` and `destroy` are for `members: create` roles.

`members` prints one JSON object per line — `{"id": "...", "host": "10.0.0.22", "role": "payments", "state": "started"}`, where state is started, stopped, maintenance or error — and `create` prints the new member the same way. A script that exits non-zero fails the command, and the last line of its stderr is the error dash shows.

```yaml
autoscale:
  provider:
    exec:
      members: bin/pool-members
      start: bin/pool-start
      stop: bin/pool-stop
      create: bin/pool-create
      destroy: bin/pool-destroy
```

## Controller

How `dash autoscale run` ticks. Every `interval` seconds (default 10, at least 5) it reads the pool and the running containers, and scales each role with a `scale/schedule` or a `scale/signal` toward its target through `dash scale set`, under the deploy lock. A tick waits up to `lock_wait_timeout` seconds (default 60) for a lock someone else holds, then holds the role until the next tick. Schedule crons are evaluated in `timezone`, an IANA name (default UTC; this example evaluates them in Stockholm time). `controller` names the ops host that runs it and keeps its state (see below); without it, the state lives on the primary role's first host.

`redis`, `postgres` and `prometheus` are where signals and guards read from (see `scale/signal` and `scale/hold_when` in dash docs role): a sidekiq signal reads Redis, a pgbus signal and a postgres guard read Postgres. Each `url` is a secret (a one-element array) or a literal URL, read from the machine the controller runs on. `via` names a host to tunnel the connection through over SSH, for a database only the app servers reach; `rediss://` cannot go through `via` (the certificate cannot be verified through a tunnel). Postgres reads run in a read-only transaction. `token` is an optional bearer token for Prometheus. The controller's Gemfile needs `redis-client` for Redis and `pg` for Postgres; dash does not depend on either.

```yaml
autoscale:
  provider:
    ...
  controller: 10.0.0.50
  interval: 10
  lock_wait_timeout: 60
  timezone: Europe/Stockholm
  redis:
    url:
      - REDIS_URL
    via: 10.0.0.31
  postgres:
    url:
      - DATABASE_URL
  prometheus:
    url: http://10.0.0.9:9090
    token:
      - PROMETHEUS_TOKEN
```

## Running the controller

`dash autoscale run` is a long-lived process on an ops host - a machine with a checkout of the app, its `.dash/secrets` and SSH access to the servers. Name that host in `controller` and run the controller there: it keeps its state on that host, under the app's run directory - a heartbeat, the decision log, the pauses and what it remembers between ticks (cooldowns, warmups, unreachable members) - away from the app servers that are busiest when the app is in trouble. It reaches its own state over SSH, like every other host, so the ops host needs an SSH key (and `ssh/user`) that logs into itself. Every operator's `dash autoscale status`, `history` and `explain`, `pause` and `resume`, `dash doctor` and `dash mcp` read and write it there too.

Without `controller`, the state lives on the primary role's first host. Setting or changing `controller` migrates nothing: the controller uses whatever state the selected host holds - none on a new host, so cooldowns, warmups and pauses start fresh; the files it had before, pauses included, on a host it used earlier. The old host's files stay where they were. Stop the old controller first, then check `dash autoscale status` on the new host for pauses that are missing or stale.

One controller per app and destination: a second one refuses to start while the first one's heartbeat is fresh (three intervals), unless started with `--takeover`, and the first stops at its next tick. TERM or INT lets the tick in progress finish - a member joining included - before it exits, so give the service manager more time to stop it than the slowest tick takes. A tick acts on its roles one after another, and each action may first wait `lock_wait_timeout` for the deploy lock and then join members one at a time, each within `boot_timeout` plus the app's boot - budget for the roles that can scale out together.

```ini
# /etc/systemd/system/dash-autoscale.service
[Unit]
Description=dash autoscale controller
After=network-online.target

[Service]
WorkingDirectory=/srv/myapp
ExecStart=/usr/local/bin/bundle exec dash autoscale run --metrics-port 9394
Restart=always
TimeoutStopSec=900

[Install]
WantedBy=multi-user.target
```

Or in a container, with the checkout and an SSH key mounted:

```shell
docker run -d --restart unless-stopped --name dash-autoscale \
  -v /srv/myapp:/app -w /app -v ~/.ssh:/root/.ssh:ro \
  ruby:3.4 sh -c "bundle install && bundle exec dash autoscale run"
```

`--once` runs a single tick and exits, for cron; the state on the controller host carries cooldowns and warmups from one run to the next. `--dry-run` decides and prints without acting or writing the controller's state (only the `--record` file, when given). `--metrics-port` serves Prometheus metrics at `/metrics` (on 127.0.0.1 unless `--metrics-bind` says otherwise). `dash autoscale explain ROLE` shows what the next tick would decide and why; `dash autoscale pause ROLE --for 2h` keeps the controller's hands off a role, `resume ROLE` gives it back.

> **Note:** Generated from the gem's `lib/dash/configuration/docs/autoscale.yml` — the same reference `dash docs autoscale` prints in your terminal, so this page always matches your installed version.