Server installation and maintenance

From preparing a server to the first sign-in: Docker Compose, native builds, HTTPS, startup and backups.

Choose how to install#

There are two ways.

  • Docker Compose is the simplest. The server, the database and nginx start together from prebuilt images. You need Git, Docker and Docker Compose.
  • Without Docker, if you run PostgreSQL and a web server yourself. You will have to build DiscoDrive from source.
Back to contents ↑

Preparation: server, address and HTTPS#

Before installing you need three things.

  • A computer or server that is always on, with room for files and command-line access. Backups are better kept on another device.
  • An address. For a public name, set up DNS: an A record pointing to the server's IPv4 address and AAAA to its IPv6 address, if it has one. If the server is at home, reaching it from outside depends on your router and provider.
  • A certificate for that name. On first start DiscoDrive creates a temporary self-signed one: it is enough to try the installation, but browsers will warn about it and some apps will refuse to connect. For everyday use, get a free Let's Encrypt certificate as described below. Without automatic renewal, the cloud will stop opening when the certificate expires.

DiscoDrive works only over HTTPS, the first setup included. Only the web server's HTTPS port should be reachable from outside. Do not expose the database port or DiscoDrive's internal HTTP port.

Back to contents ↑

Docker: download the server#

You need Git, Docker and Docker Compose installed.

Run the commands below on the server. They download the source and create the .env settings file from the example. Run all later docker compose commands from this same folder.

git clone https://github.com/discodrive-cloud/discodrive.git
cd discodrive
cp .env.example .env
Back to contents ↑

Docker: passwords and storage#

  1. Open .env in a text editor. Set POSTGRES_PASSWORD and put the same password into DATABASE_URL. A password made of random hexadecimal characters is easiest: it needs no encoding in the connection string.
  2. Generate a key for JWT_SECRET and paste the result into .env:

    openssl rand -base64 48
  3. Create SETTINGS_ENCRYPTION_KEY the same way. The key must be exactly 32 bytes long — this command prints exactly 32 characters:

    openssl rand -hex 16
  4. In BASE_DOMAIN, put the cloud's name without https:// and without a path. Leave STORAGE_ROOT=/data as it is: in the standard Compose setup, the data folder next to the Compose file is mounted there.
  5. To have the address work without a port number, set NGINX_HTTPS_PORT=443. The default is 8443, in which case the port has to be added to the address.
  6. For the first start, set XACCEL_ENABLED=false so that the DiscoDrive server sends files rather than nginx. Serving through nginx can be turned on later, once nginx is allowed to read the storage.
  7. Set your time zone in TZ. If the default storage limits and retention periods do not suit you, change them using the reference below.
  8. Save .env and restrict access to it:

    chmod 600 .env

Keep the keys somewhere safe and do not change them between restarts: without the original encryption key, stored secret settings cannot be read.

Back to contents ↑

Docker: first start#

  1. You don't need a certificate up front: on first start a self-signed one appears in deploy/nginx/certs as dev.pem and dev-key.pem. If you already have a real certificate, put it there before starting, under the same names: the full chain as dev.pem and the private key as dev-key.pem. If your certificates are already in the folder, they won't be overwritten.
  2. Never share the private key. If you replace the certificate by hand, reload nginx:

    docker compose exec nginx nginx -s reload
  3. Start the containers and check that all three are running: app, postgres and nginx. The server image is downloaded ready-made; nothing needs to be built.

    docker compose up -d
    docker compose ps
    docker compose logs --tail=100 app nginx postgres
  4. If a container stops, look at its log. The usual causes are missing keys, a wrong database password or a busy HTTPS port. The init container starts first: it creates the certificate if there isn't one yet, prepares the data folder for the server and exits. Seeing it stopped is normal.
  5. If the data folder already holds files, for example because you are moving existing storage over, init won't change their owner and stops the start-up. Hand the folder to the server user (UID and GID 65532) and start again:

    sudo chown -R 65532:65532 data
    docker compose up -d

The chown command assumes ordinary Docker. With rootless mode or userns-remap, you need the user ID on the host, which differs from 65532.

To build the image from source instead of downloading it, start it like this:

docker compose up -d --build
Back to contents ↑

First start: create the administrator#

  1. On the server, in the project folder, read the one-time code. Without Docker, it is in .bootstrap/setup-token inside the storage folder:

    sudo cat data/.bootstrap/setup-token
  2. Open the cloud's address over HTTPS. If you kept the default port, add :8443 to the address; with 443, no port is needed.
  3. Enter the code, the administrator's email and a password. Once setup is complete, the code file deletes itself.
  4. Sign in, upload a small file and download it again — that tells you everything works.

For everyday work, create an ordinary account and keep the administrator account for management.

If access to the cloud is lost, the server owner can use a backup or the steps in “Recovering administrator access”.

The list of users in the admin panel: email, role, space used and quota for each.
The admin panel, where users are created and quotas set.
Back to contents ↑

A real certificate: Let's Encrypt#

Let's Encrypt issues free 90-day certificates, and certbot renews them on its own. Below is the setup for a Docker installation: certbot runs on the server itself and hands each renewed certificate to DiscoDrive.

First, Let's Encrypt checks that the name is yours. Over port 80 — if the server is reachable from the internet under that name and port 80 is open or forwarded on your router; the standard Compose setup leaves this port free. Over DNS — if the server is at home behind a router or you can't open ports; you will need API access to your domain's DNS. certbot has plugins for Cloudflare, DigitalOcean, OVH, Route 53 and other providers.

  1. Install certbot from your system's packages:

    sudo apt install certbot
  2. Create /usr/local/bin/discodrive-cert-hook with the contents below. Every time a certificate is issued or renewed, it copies it into deploy/nginx/certs and reloads nginx. Replace /opt/discodrive with the folder you downloaded DiscoDrive into.

    #!/bin/sh
    set -e
    DD=/opt/discodrive
    cp -L "$RENEWED_LINEAGE/fullchain.pem" "$DD/deploy/nginx/certs/dev.pem"
    cp -L "$RENEWED_LINEAGE/privkey.pem" "$DD/deploy/nginx/certs/dev-key.pem"
    chmod 600 "$DD/deploy/nginx/certs/dev-key.pem"
    cd "$DD" && docker compose exec -T nginx nginx -s reload
  3. Make the script executable:

    sudo chmod +x /usr/local/bin/discodrive-cert-hook
  4. Port 80 check: get the certificate, putting in your cloud's name and your email. You will be warned there if a renewal fails.

    sudo certbot certonly --standalone \
      -d cloud.example.com -m you@example.com --agree-tos \
      --deploy-hook /usr/local/bin/discodrive-cert-hook
  5. DNS check — instead of the previous step. Create an API token at your provider that can edit records in this zone, install the certbot plugin and get the certificate. A Cloudflare example:

    sudo apt install python3-certbot-dns-cloudflare
    sudo install -m 600 /dev/null /root/cloudflare.ini
    echo 'dns_cloudflare_api_token = <API_TOKEN>' | sudo tee /root/cloudflare.ini > /dev/null
    sudo certbot certonly --dns-cloudflare \
      --dns-cloudflare-credentials /root/cloudflare.ini \
      -d cloud.example.com -m you@example.com --agree-tos \
      --deploy-hook /usr/local/bin/discodrive-cert-hook
  6. Open the cloud in a browser — the certificate warning should be gone. Check that renewal will work:

    sudo certbot renew --dry-run

The certbot package installs a system timer that checks expiry twice a day and renews in good time. The script then replaces the files and reloads nginx by itself.

If the cloud is reachable only inside a Tailscale network, the tailscale cert command issues a certificate for its ts.net name. Put the files in the same folder as dev.pem and dev-key.pem.

Back to contents ↑

Without Docker: building#

Building needs Go 1.25 or later and Node.js 22 or later; running needs PostgreSQL 16 or later.

  1. Download the server source as in “Docker: download the server” and go into the discodrive folder.
  2. Build the web interface first, then the server. The result is a single executable, discodrive, with the web interface built in.

    cd web
    npm install
    npm run generate
    cd ..
    CGO_ENABLED=0 go build -trimpath -o discodrive ./cmd/server

Run the server under a dedicated system account that can reach only its own files and the storage.

Back to contents ↑

Without Docker: database, settings and HTTPS#

  1. As a PostgreSQL administrator, create the user and the database. Choose a password for the disco user — you will need it in the connection string.

    createuser disco --pwprompt
    createdb discodrive --owner disco
  2. Create a folder for files and give the DiscoDrive account write access to it.
  3. Save the settings to a separate file with restricted access, such as /etc/discodrive.env, replacing the values in angle brackets with your own. If the database password contains URL special characters, encode them. Create the keys with the same commands as in “Docker: passwords and storage”.

    DATABASE_URL=postgres://disco:<PASSWORD>@localhost:5432/discodrive?sslmode=disable
    JWT_SECRET=<GENERATED_JWT_SECRET>
    SETTINGS_ENCRYPTION_KEY=<GENERATED_32_BYTE_KEY>
    BASE_DOMAIN=cloud.example.com
    APP_HOST=127.0.0.1
    APP_PORT=8080
    STORAGE_ROOT=/var/lib/discodrive/data
    XACCEL_ENABLED=false
  4. If the HTTPS proxy runs on the same machine, keep APP_HOST=127.0.0.1 and point the proxy at 127.0.0.1:8080. The proxy must send X-Forwarded-Proto set to https and preserve the Host header. There is an example in the next section.
  5. If the proxy is on another machine, put its address or subnet in TRUSTED_PROXY_CIDRS and block access to DiscoDrive from everywhere else.
  6. To have the server start on its own, set up automatic startup as described below. For a one-off run, export the settings into the environment and run ./discodrive. Then complete the first setup over HTTPS.
Back to contents ↑

Without Docker: example HTTPS proxy#

An example for nginx on the same machine as DiscoDrive. Replace the site name and certificate paths, add the block to your nginx configuration, check it with nginx -t and reload nginx. The private key should be readable only by the system processes that need it.

In this example the DiscoDrive server sends files rather than nginx, so XACCEL_ENABLED=false.

server {
    listen 443 ssl;
    server_name cloud.example.com;
    ssl_certificate /etc/ssl/discodrive/fullchain.pem;
    ssl_certificate_key /etc/ssl/discodrive/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    client_max_body_size 0;
    access_log off;
    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_http_version 1.1;
        proxy_request_buffering off;
        proxy_buffering off;
        proxy_read_timeout 3600s;
    }
}
Back to contents ↑

Starting automatically on Linux#

This section is for installations without Docker. If you installed with Docker, the containers already start on their own; skip to updates and backups.

  1. Create the discodrive system user, copy the program to /usr/local/bin, create /var/lib/discodrive/data and make /etc/discodrive.env readable by root only. If your paths differ, change them here, in the service file and in the settings.

    sudo useradd --system --user-group --home-dir /var/lib/discodrive --shell /usr/sbin/nologin discodrive
    sudo install -m 755 discodrive /usr/local/bin/discodrive
    sudo install -d -o discodrive -g discodrive -m 750 /var/lib/discodrive/data
    sudo chown root:root /etc/discodrive.env
    sudo chmod 600 /etc/discodrive.env
  2. Check that /etc/discodrive.env has one setting per line, as KEY=value, without export.
  3. Create /etc/systemd/system/discodrive.service:

    [Unit]
    Description=DiscoDrive
    After=network.target postgresql.service
    
    [Service]
    User=discodrive
    ExecStart=/usr/local/bin/discodrive
    EnvironmentFile=/etc/discodrive.env
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
  4. Enable the service and check its status and log:

    sudo systemctl daemon-reload
    sudo systemctl enable --now discodrive
    sudo systemctl status discodrive
    sudo journalctl -u discodrive -n 100

The service starts when the server boots and restarts after a crash. To update the program, stop the service, replace the file and start it again.

Back to contents ↑

Updates and backups#

A backup is a copy of the PostgreSQL database and the storage folder, hidden service files included. For a consistent copy, the easiest way is to stop app and nginx for a while and leave the database running.

Keep settings and keys separately, and the settings encryption key away from the database copy. Every so often, check on a separate installation that you can actually restore from the backup. Device sync is not a backup.

Make a backup before updating: the database schema is upgraded when the new version starts, and going back to the old program does not roll the database back.

  • Docker: in the project folder, run the commands below, then check the containers, signing in and downloading a file. To update only when you decide to, pin the version with DISCODRIVE_VERSION in .env.

    git pull
    docker compose pull
    docker compose up -d
  • Without Docker: build the new version, stop the service, replace the program and start it again.

docker compose down stops the installation and keeps the database data.

Back to contents ↑

Recovering administrator access#

  • The one-time code is lost and setup isn't finished. Delete the code file and restart app — the server issues a new code and the old one stops working:

    sudo rm data/.bootstrap/setup-token
    docker compose restart app
  • The last administrator account was deleted. First-time setup will not reopen — that protects you from strangers. Restore the database from a backup, or make an existing account an administrator, putting in its email:

    docker compose exec -T postgres sh -c 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB"' <<'SQL'
    UPDATE users SET role = 'admin' WHERE email = 'you@example.com';
    SQL

Without Docker, the code is in .bootstrap/setup-token inside the storage folder, and the query runs in plain psql. Don't try to reopen first-time setup by editing the database.

Back to contents ↑

If the installation does not work#

  • app does not start. Look at its log, and check that PostgreSQL is reachable, the connection string and the key lengths. When asking for help, do not post your whole .env.
  • Compose says service "init" didn't complete successfully. Run docker compose logs init: most often the data folder already holds files and the server needs access to it, see “Docker: first start”.
  • nginx does not start. Look at the init and nginx containers' logs and check that the chosen HTTPS port is free. If you supplied your own certificate, check that both files are there under the right names and readable.
  • The browser warns about the certificate. With the self-signed certificate this is expected — replace it with a real one, see the Let's Encrypt section. With a real one, check the site name, the expiry date and that the chain is complete. Fix the certificate rather than turning off the check.
  • Files are listed but do not download. With XACCEL_ENABLED=true, nginx has to be able to read the storage. Give it access through a dedicated group or an ACL that accounts for the container's user, rather than opening the storage to every user on the machine.
  • Changed .env — recreate the containers with docker compose up -d. Replaced the certificate — reload nginx.

If you ask for help and share logs with someone, remove passwords, tokens and internal addresses from them first.

Back to contents ↑

Configuration reference

Use .env for Docker or process environment variables for native installations. The full example ships with the source.

Environment variables
VariableWhat it sets
DATABASE_URLConnection to PostgreSQL, where the index and the metadata live.
JWT_SECRETThe key sessions are signed with.
SETTINGS_ENCRYPTION_KEYThe key the stored service settings are encrypted with.
BASE_DOMAINThe domain this deployment answers on.
APP_HOSTThe address the service listens on.
APP_PORTThe port the service listens on.
STORAGE_ROOTThe storage folder. Files in it have the same names as in the interface.
STORAGE_TOTAL_GBTotal storage limit in GB. Once it is used up, writes stop.
DEFAULT_USER_QUOTA_GBQuota for a new user in GB. It can be changed later in the admin panel.
TRASH_DAYSHow many days files stay in the trash.
VERSION_KEEPHow many versions of a file to keep. Zero keeps none.
XACCEL_ENABLEDServe files through nginx. DiscoDrive checks permissions, nginx sends the file.
SAVED_MAX_DOWNLOAD_MBMaximum size, in MB, of a file the server downloads from a link.
DISCODRIVE_VERSIONDocker only: the server image version, such as 0.1.0. Defaults to the latest.

.env.example · Server README