﻿# Running in production

> These notes apply to every deployment type and every database.

Source: https://workwise-solutions.net/docs/installation/operations/ · Language: en · Hungarian version: https://workwise-solutions.net/hu/docs/installation/operations/

These notes apply to every deployment type and every database.

## Health check

`GET /health` answers `200 {"status":"Healthy"}` without sign-in as soon as the application serves requests (after the start-up migrations). It touches nothing else. Use it for load balancers, monitoring and Kubernetes probes; give liveness probes a generous initial delay, because the first start runs the migrations.

## Sessions

The keys that protect sign-in cookies are stored in the database. Sessions therefore survive restarts, container recreation and upgrades, and are valid on every server. Anyone with a copy of the database could create valid sign-in cookies, so protect backups.

## Running more than one server

Several application servers can share one database:

- **Database**: SQL Server, PostgreSQL or MySQL. SQLite supports one server only.
- **Cache**: `Redis` or a database cache. With the default `InMemory` cache, permissions, the licence status, master data lists and the OAuth sign-in state would differ between servers; the application logs a warning about this at start.
- **File storage**: a cloud storage, not the server disk.
- **Same settings everywhere**: identical `appsettings.json`, including signing keys and `PublicBaseUrl`.
- **Migrations** at start run under a cross-node lock: one server migrates, the others wait.
- **Scheduled jobs run once per occurrence across all servers**: before running, a server claims the occurrence in the database, so no e-mail, Slack/Teams message or Számlázz.hu call is duplicated. Keep the servers' clocks synchronised and in the same time zone, and use job intervals of 1 day or less. The *Run-once claim cleanup* job deletes old claims (daily 04:15, keeps 7 days).
- App configuration changes reach the other servers within about 10 seconds.

![WorkSmartHub on several servers](https://workwise-solutions.net/docs/images/diagram-multi-node-en.png)
*Several servers share one database, one cache and one cloud file storage; scheduled jobs run once per occurrence.*

## Shutdown

On stop, the application gives its background jobs 45 seconds and then closes the database. Allow it 60 seconds or more: `--stop-timeout 60` in Docker, `TimeoutStopSec=75` in systemd, `shutdownTimeLimit="60"` under IIS.

## Log levels

The minimum log levels come from `appsettings.json` (`Serilog:MinimumLevel`) or environment variables, unless **App Konfiguráció → Log Szintek** overrides them for all servers. Every change there is recorded with the administrator's name. Never run Debug or Verbose in production except briefly: they write far more data, which can include personal data, and fill the disk. Request logs never contain credential query parameters.

## Stored secrets

Secrets entered in the user interface (notification channel and file storage credentials, the Számlázz.hu keys, the HashiCorp Vault token) are write-only: they are never shown again, and an empty field keeps the stored value. When the target of a secret changes (SMTP host or port, MinIO server, S3 region, Azure account, SharePoint tenant, Vault URL, the type, or SSL turned off), the secret must be entered again. To rotate a secret, create a new one at the provider, enter it, then revoke the old one.

## Security checklist

- Own signing keys, HTTPS, `SecureCookie: true`, `PublicBaseUrl` set ([Configuration](https://workwise-solutions.net/docs/installation/configuration/)).
- A reverse proxy must **overwrite** `X-Forwarded-Host` and `X-Forwarded-Proto`, because the application trusts them.
- Restrict `appsettings.json` and backups to administrators.
- Review **Admin Token Menedzsment** and invalidate unused tokens.
- Keep `Swagger.Enabled` off if you do not need the API documentation.
- Keep the security headers on (**App Konfiguráció → Biztonsági fejlécek**).

## CLI

The application binary also accepts command-line verbs. `dotnet WorkSmartHub.dll --help` lists them; in the current release:

| Verb | Purpose |
|---|---|
| `run` | Runs the web application (default when no verb is given) |
| `database` | Actions on the internal database: backup, restore, clear, migrate. Migration uses the same cross-node lock as the start-up. |
| `user-store` | Queries the configured user store (useful to test a directory connection) |
| `help`, `version` | Help and version information |

Run the verbs in the application folder with the same `appsettings.json`, and stop the application before a restore.
