# Deployments

> A deployment puts a release of an app on an environment's servers, one after another, checking its health on each.

**A deployment puts a release of an app on an environment's servers, one after another, and checks its health on each before going on.**

Started by: a pipeline's stage, or Deploy in the Environments app
Goes to: your hosts, over SSH
Runs as: a systemd service, from an archive or a Docker image

## What's deployed {#what}

A program's release is packed as an **archive**, its `Archive` packager's: the program, its libraries and its runtime, such as its own JDK or Python, so the server needs nothing installed. A program needs no `packager` line for it. `Archive: { platforms = [linux-x64, linux-aarch64] }` packs it for more platforms, and a `scripts/run.sh` in the project replaces how it starts. A [custom build's service](../languages/custom.md#service) can carry tools too, each archive with its platform's.

With `packager = Docker`, it's a **Docker image** instead: the same layout under `/opt/<name>`, on a base image a build dependency names, such as `DebianSlim`. The server runs it in Docker, under the same systemd service, so its steps, its health check, Restart and its journal are an archive's, its fourth step **Load the image**. Docker is root, so an image goes only to hosts whose group has **System services** on, with Docker installed. See [Run your service as a Docker image](../guides/docker-images.md).

## Server by server {#servers}

An environment runs one deployment at a time. Its servers go one after another, in order, and each one takes these steps:

1. Connect to the server
2. Check what it runs
3. Upload the release
4. Unpack it
5. Write the service's unit
6. Restart the service
7. Check its health
8. Keep the newest five releases

A server that fails stops the deployment, and those after it keep what they run. A server that isn't ready yet gets the release once it is, and one that joins later gets what the others run; while the environment is [locked](environments.md#locks), once it's released.

When the environment has [sidecars](sidecars.md), each host's turn ends with a step for each sidecar whose copy there needs its picked release or new values, such as `(9/9) LogShipper/Prod #31 → #33`, and a step that takes off a sidecar it no longer has. A copy that fails is a warning, never the deployment's failure.

## Health, and putting it back {#health}

A release that doesn't come up healthy is put back on its own, on that server, and the deployment stops. **Deploy settings** say how to tell:

| Setting | What it does |
|---|---|
| `health-url` | the address that must answer, such as `http://localhost:8080/health`; an image's as its container sees itself, asked at the container's address |
| `health-timeout` | how long to wait for it (default 60 s) |
| `systemd` | `user` (the default) or `system` |
| `stop-timeout` | how long it gets to stop; an image's hooks and program within it |
| `ports`, `volumes` | an image's: `8080:8080` publishes a port, `/srv/data:/data` mounts a folder |

## Hooks {#hooks}

Scripts in the project's `scripts/` run on the server around the restart, and an image's inside its container, by its entrypoint, with what the image has:

| Script | When | If it fails |
|---|---|---|
| `pre-start.sh` | before it starts | the deployment fails |
| `post-start.sh` | after it starts | the deployment fails |
| `pre-stop.sh` | before it stops | a warning |
| `post-stop.sh` | after it stops | a warning |

## What the service gets {#environment}

The environment's **Configuration**, as variables, and where it runs: `PLINTO_REGION`, `PLINTO_ENV` and `PLINTO_STAGE`, from its **Instance**, which pick the lines of its [configuration files](../reference/configuration.md#runtime); `PLINTO_APP`, `PLINTO_ENVIRONMENT` and `PLINTO_VERSION`; and the host it runs on, `PLINTO_HOST` and `PLINTO_ADDRESS`, with the app's `PLINTO_PORT` and `PLINTO_HEALTH_URL`, which [a load balancer of your own](../guides/load-balancer-hooks.md) takes it out and puts it back with.

## Rolling back {#rollback}

On an environment's list of deployments, **Roll back to this** deploys an earlier release again, as a new deployment:

> Nothing else changes: it gets the environment's configuration as it is now, and the pipeline's next candidate deploys over it.

## The deployment page {#page}

Each deployment has a page: its servers and each one's steps, and the log, live, per server or as the **Whole log**.

- [Environments](environments.md): where it deploys, and with what
- [Hosts](hosts.md): the servers
- [Pipelines](pipelines.md): the stages that deploy
