# ScalWS Console: installation and operation

URL: https://scalws.com/docs/console/operations/
Source: `docs/console-operations.md` in the ScalWS repository

ScalWS Console is part of the standard ScalWS distribution: the DEB, RPM and APK packages
contain `/usr/bin/scalws-console` and
`scalws-console.service`, next to `scalwsd`, `scalws-controller` and `scalwsctl`.

## Install (packages)

The package's post-install step (`packaging/scripts/postinstall.sh`):

1. creates `/etc/scalws/console/credentials` (0600, root) with user **`admin`** and a
   random 24-character password, unless the file exists;
2. prints, once, to the operator running the installer:

   ```text
   ScalWS Console administrator account created
     address:  https://<server-address>:8090
     user:     admin
     password: sudo grep '^admin:' /etc/scalws/console/credentials | cut -d: -f3
     file:     /etc/scalws/console/credentials (0600)
   ```

   The password itself is never printed: package managers record the installer's
   terminal (apt keeps it in `/var/log/apt/term.log`, readable by group `adm`).

3. enables and starts `scalws-console.service`.

Read the password from the credentials file with the command shown. Upgrades keep the
file.

Manual equivalent (tarball installs, containers):

```sh
scalws-console init-credentials --credentials /etc/scalws/console/credentials \
    --url "https://$(hostname -I | awk '{print $1}'):8090"
systemctl enable --now scalws-console
```

If `scalws-console run` starts without a credentials file it creates one the same way and
logs only the file's path (development fallback).

## systemd unit

`/usr/lib/systemd/system/scalws-console.service` runs:

```sh
scalws-console run --controller-config /etc/scalws/controller.yaml \
    --credentials /etc/scalws/console/credentials \
    --state-dir /var/lib/scalws-console --listen 0.0.0.0:8090 \
    --controller-restart-command "systemctl restart scalws-controller"
```

as root with a reduced capability set and a read-only file system except `/etc/scalws`,
`/var/lib/scalws-console`, `/srv/www` and `/home` (see `docs/console-security.md`, "Privileges"). It starts
after the controller but does not depend on it: with the controller stopped the console
shows it as unavailable.

## Options

| Option | Default | Meaning |
|---|---|---|
| `--listen` | `0.0.0.0:8090` | HTTPS address |
| `--controller-config` | `/etc/scalws/controller.yaml` | gives the controller socket, the ScalWS configuration path and `instances.min/max` |
| `--controller-socket`, `--scalws-config` | from the controller configuration | overrides |
| `--controller-log` | none | controller log file for the Logs page (JSON lines) |
| `--credentials` | `<state-dir>/credentials` | accounts file |
| `--state-dir` | `/var/lib/scalws-console` | history, audit log, generated TLS certificate |
| `--tls-cert`, `--tls-key` | self-signed in `<state-dir>/tls/` | PEM certificate chain and key |
| `--tls-name` | | extra names/addresses for the generated certificate |
| `--allow` | all | allowed client addresses or CIDRs (repeatable) |
| `--session-idle-minutes` | 30 | session idle timeout |
| `--health-timeout-secs` | 120 | how long an apply waits for the new generation (or the restarted controller) |
| `--controller-binary` | next to `scalws-console` | scalws-controller, for `check-config` and `config-schema` of controller.yaml |
| `--webd-binary` | next to `scalws-console` | scalwsd, to check configuration drafts (never taken from controller.yaml, which console users can edit) |
| `--ctl-binary` | next to `scalws-console` | scalwsctl, to add and remove sites on the Domains page |
| `--panel-status`, `--panel-state` | `/var/lib/scalws-panel/status.json`, `/var/lib/scalws-panel/state.json` | panel mode: status of the last sync and the state file |
| `--service-sandbox`, `--service-rw` | off | service sandbox for systems without systemd (OpenRC), see [sandbox](https://scalws.com/docs/guide/sandbox/) |
| `--controller-restart-command` | none | restarts the controller after a controller.yaml change, e.g. `systemctl restart scalws-controller`; without it the validated file is written and waits for a restart |

## First sign-in

Open `https://<server-address>:8090`. With the generated self-signed certificate the
browser warns once; replace it with a real certificate (`--tls-cert/--tls-key`, e.g. the
host's ACME certificate) for production. Sign in as `admin` with the password from the
installer.

## Accounts

Edit `/etc/scalws/console/credentials` (keep 0600):

```text
admin:administrator:<password>
ops:operator:$argon2id$v=19$m=19456,t=2,p=1$...
dev:developer:<password>
look:viewer:<password>
```

Roles: `administrator`, `operator`, `developer`, `viewer` (`docs/console-rbac.md`).
`echo 'new password' | scalws-console hash-password` prints a hash to use instead of plain
text. Changes apply on the next request; sessions of changed or removed accounts end. A
file readable by group or others disables sign-in until it is fixed (logged).

## Upstreams view

Monitor, Upstreams (capability `server.read`) lists every member of every upstream pool
with its weight, requests in flight, consecutive failures and state (`ok`, or `ejected`
while passive health keeps it out), refreshed every 5 seconds. The console reads it from
the controller (`GET /upstreams`), which asks one serving instance; when the controller or
every instance is unreachable the view shows the error (502). Pools themselves are edited
under Configuration, Upstream pools; members of `members_from: api` pools are set through
the admin API (`scalwsctl upstreams set`), not in the configuration.

## Domains

Manage, Domains lists the sites of this server: each site file under
`/etc/scalws/sites.d/` with its other domains (`www.`, aliases), type (static, PHP, proxy,
redirect), target (document root, PHP-FPM pool, upstream, redirect address), HTTPS
certificate (valid with days left, pending, or the Let's Encrypt error) and DNS: whether
the domain's A/AAAA records point at one of this machine's addresses ("points
elsewhere" is also what a proxy or CDN in front of the server looks like). Applications
written in `scalws.yaml` itself are listed separately and edited under Configuration,
Sites. Reading the page needs `config.read`.

Administrators (`sites.manage`, with a password confirmation) add and remove domains:

* **Add domain**: domain, type, and for PHP the PHP-FPM socket (the ones in `/run/php`
  are offered), for a proxy the upstream address, for a redirect the target. Under
  Advanced: the document root (default `/srv/www/<domain>`, which is created with a
  placeholder page; only below `/srv/`, `/var/www/` or `/home/`; the page warns when user `scalws` cannot read it), `www` handling, other domains and
  a redirect to HTTPS.
* **Remove**: after typing the domain to confirm; the site file is kept as a hidden backup
  next to it, the document root is not touched.

The console runs `scalwsctl site add|remove --json` for this, the same path as the command
line: the site file is written, the whole configuration checked, the server reloaded
through the controller, and everything is taken back when the check or the reload fails.
Changes are serialised with configuration applies and recorded in the audit log
(`site.add`, `site.remove`). Certificates come from the controller (`GET /certs`, one
serving instance asked); without an answer the page says so and still lists the sites.

### Domains in panel mode

When [panel mode](https://scalws.com/docs/guide/control-panels/) is on, the sites that `scalwsctl panel sync`
wrote (`sites.d/panel/`) are shown read-only, marked with the panel's name, under a banner
with the last sync, the skipped domains, the warnings and the sync error. Adding a domain
and removing a panel-managed one are refused (HTTP 409: do it in the panel, cPanel or DirectAdmin).

## Files

| Path | Content |
|---|---|
| `/etc/scalws/console/credentials` | accounts (0600) |
| `/var/lib/scalws-console/audit.jsonl` | audit log (append-only, 0600) |
| `/var/lib/scalws-console/history/` | every configuration applied or found, with index |
| `/var/lib/scalws-console/tls/` | generated certificate and key (0600) |

Back up `/var/lib/scalws-console` with `/etc/scalws`.

## Upgrade, removal

Package upgrades replace the binary and restart the unit (sessions end; drafts are lost;
history and audit stay). Removal stops and disables the unit; the state directory and the
credentials file are left in place.

## Development / demo deployment

The development host runs a demo stack separate from benchmark and soak runs:
a controller with its own state directory, socket, configuration, CPUs and ports, and the
console on port 8090 managing it (`docs/console-architecture.md`). Every process of that
stack runs under `taskset -c 6-7 nice -n 10`.

## Overhead

The console is not on the request path. Its telemetry is one controller `status` call per
2 s per open browser tab (paused for hidden tabs); measured overhead on the data plane is
reported in the console test report.
