# Deployment guide

This guide explains how a Shelftara installation is put together so that a
server can be reproduced or repaired by hand.

## What the server needs

| Component | Minimum | Notes |
| --- | --- | --- |
| Go | 1.23 | Only to build the binary, 1.26 is recommended. |
| MySQL or MariaDB | 8.0 / 10.6 | The schema is created automatically. |
| nginx | 1.18 | Reverse proxy and static assets. |
| systemd | 245 | The service is managed by systemd. |
| curl | any | Used for the health check of the installer. |

## Layout of an installation

| Path | Content |
| --- | --- |
| /opt/shelftara/bin/shelftara | The compiled server. |
| /opt/shelftara/storage/uploads | The uploaded files of the tenants. |
| /opt/shelftara/logs | The log file of the service. |
| /etc/shelftara/shelftara.env | The configuration, readable by root only. |
| /etc/systemd/system/shelftara.service | The unit of the service. |
| /etc/nginx/sites-available/shelftara.conf | The site of the proxy. |

## Order of the start

1. The unit reads /etc/shelftara/shelftara.env.
2. The server opens the database and migrates the schema.
3. The platform administrator, the plans and the module catalogue are created
   when they do not exist yet.
4. The demo workspace is filled when SEED_DEMO=true.
5. The server listens on PORT and answers /healthz.

## Behind a proxy

The nginx site of the installer forwards the Host header and the
X-Forwarded-For and X-Forwarded-Proto headers. The server reads the host from
the Host header, which is what resolves the workspace of a subdomain, and it
records the address of the socket in the session and in the audit log. The
uploads are limited to 64 megabytes, which matches the limit of the
application.

## Behind a TLS terminator

When a certificate is installed, set COOKIE_SECURE=true in
/etc/shelftara/shelftara.env and restart the service:

~~~sh
sed -i 's/^COOKIE_SECURE=.*/COOKIE_SECURE=true/' /etc/shelftara/shelftara.env
systemctl restart shelftara
~~~

## Backup

~~~sh
mysqldump --single-transaction shelftara > shelftara-$(date +%F).sql
tar czf shelftara-storage-$(date +%F).tar.gz -C /opt/shelftara storage
~~~

## Reverse proxy of a second domain

Add a server block that points to the same port and give the application
the matching APP_URL and BASE_URL.
