# How it works

What the image does when a container starts, and why. Reading this once answers most questions about volumes, versions and passwords.

## Two folders

| Folder | Holds | Writable |
|---|---|---|
| `/app` | the program of the image's build, exactly as the CrushMFT 27 download has it, with its signed `release.txt` | no, it belongs to the image |
| `/app/CrushMFT27` | the **working folder**: a CrushMFT folder like any installation. The program at its top (`CrushMFT.jar`, `CrushLauncher.jar`, `plugins/`, `WebInterface/`, `release.txt`), earlier and staged versions in `backup/updates/`, and the server's data beside them: users, settings (`prefs.XML`), jobs, logs, keys | yes, it is your volume |

CrushMFT 27 always runs the program at the top of its working folder, through its launcher, which checks the signature of `release.txt` and the size and SHA-256 of every file it names before it starts anything. This is the same on Windows, macOS, Linux and in a container. In a container, the image brings one version, and the volume may already run another.

## What a start does

The image starts `CrushContainer.jar`, a small start program, which does four things and then hands over to CrushMFT's launcher:

1. **It checks the working folder.** If `/app/CrushMFT27` can't be written (a volume owned by another user), it stops at once with exit code 1 and says so. See [Data and volumes](Data-and-Volumes.md#ownership).
2. **It puts the image's version in place,** the way an update with a restart does: the files of the image's `release.txt` are copied into `backup/updates/v<version>/` in the volume (each checked by its size and SHA-256 while it is copied, into a hidden folder first, renamed into place at the end), and `backup/updates/next` names that version. CrushMFT's launcher then puts it at the top when it starts: the version that was at the top is kept in `backup/updates/` as the one to go back to, and the files a customer may change (`favicon.ico`, `expired.html` and `mime_types.txt` in `WebInterface/`, a changed starter) are kept.
3. **It chooses the version.** By CrushMFT's version (`27.0.0_289` is newer than `27.0.0_288`):

   | The volume | Runs | Kept to go back to |
   |---|---|---|
   | is new | the image's version | none |
   | runs an older version | the image's version | the volume's older one |
   | runs the same version | that version; nothing is copied | unchanged |
   | runs a newer version (CrushMFT's updater fetched it) | the volume's newer version | the image's, when there is none |
   | has a newer version staged for its next start | that newer version | |

   A version that failed to start on this volume before is marked bad (`backup/updates/bad`) and is never put in place here. A start stopped half way leaves only the hidden copy, which the next start removes and makes again.

4. **It sees to the first admin.** The arguments `-ad crushadmin` (the image's default) create the admin user `crushadmin` on the very first start. Its password is taken, in this order, from:

   | Source | |
   |---|---|
   | `CRUSHFTP_ADMIN_PASSWORD_FILE` | the file this variable names (a Docker or Kubernetes secret) |
   | `CRUSHFTP_ADMIN_PASSWORD` | the password itself. It is written to a private file for the server, which is removed again as soon as the user exists. |
   | `PASSFILE` | the file this variable names, `/app/CrushMFT27/passfile` by default, if it is there and not empty |
   | none of these | 20 random characters, written to `PASSFILE` (readable only by the server's user) and printed once in the log |

   A password file that is missing, empty or can't be read by the server's user stops the start with exit code 1 and a message saying which and why; nothing is created. (An empty `PASSFILE` is simply replaced by a random password.)

   There is no default password. Once the user exists, none of this is used again: changing the variable or the file later does not change the password ([Operations](Operations.md#reset-the-admin-password) shows how to reset it).

Then CrushMFT's launcher (the image's, or the volume's own when the volume runs a newer version) puts a staged version at the top (only the files that differ are written), checks the program there, and starts the server. A version that does not pass its check, or fails while starting, is marked bad and the version kept before it is put back and started.

On the `-fips` images there is one more step before the launcher: the volume is prepared for FIPS mode when it is not yet prepared for this version ([Images and tags](Images.md#fips-140-3-mode)).

## In the log

The start program's lines begin with `CrushContainer:`, the launcher's with a date. A new volume:

```
CrushContainer: Version 27.0.0_288 of the image put into /app/CrushMFT27/backup/updates/v27.0.0_288.
CrushContainer: A new volume: CrushLauncher's start puts version 27.0.0_288 of the image at the top.
CrushContainer: The first admin user crushadmin gets a random password, kept in /app/CrushMFT27/passfile: ...
CrushContainer: Starting /app/CrushLauncher.jar in /app/CrushMFT27.
Sat Nov 21 18:06:17 GMT 2026|Started CrushLauncher, level 3.
Sat Nov 21 18:06:17 GMT 2026|Version 27.0.0_288: 1573 file(s) at the top replaced.
Sat Nov 21 18:06:17 GMT 2026|Version 27.0.0_288 is at the top now.
Sat Nov 21 18:06:17 GMT 2026|Starting CrushMFT (version 27.0.0_288, copy 1)...
```

A newer image on that volume:

```
CrushContainer: The image brings version 27.0.0_289, newer than the volume's 27.0.0_288: CrushLauncher's start puts it at the top and keeps 27.0.0_288 in backup/updates/v27.0.0_288/ to go back to.
Sat Nov 21 18:06:30 GMT 2026|Version 27.0.0_289: 7 file(s) at the top replaced.
Sat Nov 21 18:06:30 GMT 2026|Version 27.0.0_289 is at the top now; version 27.0.0_288 is kept in backup/updates/v27.0.0_288/.
```

The same image again: `CrushContainer: Version 27.0.0_289, the image's, starts as before.` An older image on a volume with a newer version: `CrushContainer: The volume runs version 27.0.0_289, newer than the image's 27.0.0_288 (an in-app update): it keeps running.` (the volume's own launcher then starts it).

After these lines comes the server's own log ([Health, logs and monitoring](Health-Logs-Monitoring.md#logs)).

## While it runs

- The server runs as uid 65532, as process 1 of the container. `docker stop` sends it the stop signal; it finishes what it is doing and ends ([Operations](Operations.md#start-stop-restart)).
- A restart asked for in the admin pages ends the process with exit code **64**, and Docker (with a restart policy) or Kubernetes starts the container again.
- CrushMFT's job engine and its runners are separate Java processes in the same container. The server's heap is half of the container's memory limit (`-XX:MaxRAMPercentage=50`), so they have room ([Configuration](Configuration.md#java-memory-and-options)).
- CrushMFT's updater can fetch a newer signed version into the volume and switch to it without a restart. See [Updates and versions](Updates-and-Versions.md).

## The same in Kubernetes

The [Helm chart](Kubernetes.md) runs the same image the same way: the volume is a PersistentVolumeClaim at `/app/CrushMFT27`, the first password comes from a Secret through `CRUSHFTP_ADMIN_PASSWORD_FILE`, and there is no init container and no job.
