# Service settings

Source: https://openpanel.sh/docs/projects/settings

Every setting a service has, from its source to its servers, with its limits and the rules between them.

A service's settings say what it runs, how it is reached and where. Changing them needs deploy access to the project, and a change takes effect at the service's **next deploy**: until then the running deployment keeps the settings it was made with.

## Change a setting [#change-a-setting]

<Tabs items={["Console","CLI","API"]}>
<Tab value="Console">
Open the project and click the service on the canvas. Its **Settings** tab has one card for each part: **Source**, **Name**, **Build and start**, **Networking**, **Load balancer and replicas**, **Volumes**, **Health check**, **Resources** and **Servers it may run on**. Each card has its own **Save**, which sends only that card's fields. Then deploy the service from its **Overview** tab.
</Tab>

<Tab value="CLI">
```sh
openpanel services update web --project shop --balancer --replicas 3
openpanel deploy web --project shop
```

`services update` takes the same settings as `services create`, and changes only those you pass.
</Tab>

<Tab value="API">
```sh
curl -X PATCH https://openpanel.sh/api/v1/services/$SERVICE_ID \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"balancer": true, "replicas": 3}'
```

Only the fields you send change. The answer is the whole service as saved.
</Tab>
</Tabs>

`openpanel services get web --project shop` shows the settings as saved, and `GET /services/{serviceId}` returns them in full.

## Every setting [#every-setting]

| Setting | CLI | API field | Values |
|---|---|---|---|
| Name | (at create) | `name` | Up to 32 lowercase letters, digits and hyphens, starting with a letter; used once in the project, across its environments |
| Image | `--image nginx:1.27` | `source: {kind: "image", image, tag}` | Docker Hub when no registry is named; tag `latest` when none is given |
| Git repository | `--repo`, `--git-account`, `--branch`, `--path` | `source: {kind: "git", accountId, repo, branch, path}` | Branch `main` and the repository's root by default |
| Build | `--dockerfile <path>` | `build: {kind: "auto"}` or `{kind: "dockerfile", dockerfile, context}` | Git sources only; detected when not set |
| Start command | `--start "<command>"` | `startCommand` | Up to 2,000 characters; empty keeps the image's own |
| Address | `--public`, `--private`, `--no-address` | `exposure`: `public`, `private`, `none` | `none` by default |
| Ports | `--port http:3000` (repeat) | `ports: [{protocol, port}]` | Up to 20; `http`, `tcp` or `udp`; 1 to 65535 |
| Load balancer | `--balancer`, `--no-balancer` | `balancer` | Off by default; public services only |
| Replicas | `--replicas 3` | `replicas` | 1 to 100 |
| Health check | `--health http:3000:/health`, `--health tcp:5432` | `healthCheck` | See [Health checks](/docs/projects/health-checks) |
| CPU limit | `--cpus 0.5` | `resources.cpus` | 0.1 to 256 CPUs per replica; no limit by default |
| Memory limit | `--memory 512` | `resources.memoryMb` | 32 MB to 1,048,576 MB per replica; no limit by default |
| Servers | `--server <name>` (repeat) | `serverIds` | Up to 50 of your organization's servers |
| Volumes | `openpanel volumes add` | `POST /services/{serviceId}/volumes` | Up to 10; see [Volumes](/docs/volumes) |
| Environment | `--environment <name>` (at create) | `environmentId` (at create) | The production environment by default |

## Source [#source]

A service runs a **Docker image** or is built from a **Git repository**. Changing the source, for example from a repository to an image, takes effect at the next deploy like any other setting. A source that stops being Git loses its build settings.

- **Image:** the name may name a registry (`ghcr.io/acme/app`) and the tag follows a colon. See [Deploy an image](/docs/deploy/images).
- **Git:** `repo` is `owner/name` in the Git account, `branch` the branch to build, and `path` one folder of the repository for a monorepo. See [Deploy from Git](/docs/deploy/git).

A member's own Git account can be chosen only by that member. A service that already uses one keeps it when someone else changes its other settings, and its deploys go on using it.

## Build [#build]

For a Git source only. Without build settings, the build is detected from the repository. With `--dockerfile`, or `build.kind` `dockerfile` in the API, it builds with the Dockerfile at that path; the API also takes `context`, the folder sent to the build. See [How builds work](/docs/builds).

## Start command [#start-command]

The command each replica runs, in place of the image's own. It runs with `/bin/sh -c`, so the image needs a shell, and you can write it as you would in a terminal:

```sh
openpanel services update web --project shop --start "node server.js --port 3000"
```

`--start ""` in the CLI, or `"startCommand": null` in the API, goes back to the image's own command.

## Address [#address]

| Value | Who reaches the service |
|---|---|
| `public` | The internet, through OpenPanel's edge: each HTTP port at the service's [opnl.app address](/docs/domains/opnl-app) and [your own domains](/docs/domains/own-domain), each TCP or UDP port on [its own public port](/docs/tcp-udp) |
| `private` | Each port gets a port on its server's `127.0.0.1`, shown as `loopbackPort`. Carrying it into your organization's private network is being built; see [Private addresses](/docs/network/private-addresses) |
| `none` | Nobody from outside |

In every case the project's other services on the same server reach it by its name.

A public service with an HTTP port gets an opnl.app address when it is saved, and loses it when it is no longer public or has no HTTP port left. A service with [your own domains](/docs/domains/own-domain) cannot leave `public` until you remove them.

## Ports [#ports]

Each port is a protocol and the port the container listens on: `http` for websites and HTTP APIs, `tcp` for anything else on TCP, `udp` for UDP. A port is listed once per transport, and `http` and `tcp` share TCP, so `http:80` and `tcp:80` cannot both be listed.

The list you send replaces the old one, in the CLI as in the API: name every port the service should keep.

| On a service that is | An `http` port | A `tcp` or `udp` port |
|---|---|---|
| Public | Reached through its domains, with HTTPS | Gets a public port on the edge from 30000 to 32767, shown as `edgePort` |
| Private | Gets a port on its server's `127.0.0.1` from 20000 to 29999, shown as `loopbackPort` | The same |
| With no address | Reached only by the project's other services on the same server | The same |

A port keeps its `edgePort` or `loopbackPort` across changes as long as it still needs one.

## Load balancer and replicas [#load-balancer-and-replicas]

`replicas` is how many copies of the service run. Four rules decide what is allowed:

| Service | Replicas |
|---|---|
| Public, load balancer off | 1 |
| Public, load balancer on | 1 to 100, and the edge balances over them |
| Private | 1, and no load balancer |
| No address | 1 to 100, without the load balancer |
| With a volume | 1, and no load balancer, whatever its address |

See [Load balancer on or off](/docs/load-balancing) and [Replicas](/docs/load-balancing/replicas).

## Resources [#resources]

Limits per replica: `cpus` is a share of the server's processors (`0.5` is half of one), `memoryMb` the most memory in megabytes. A replica that goes over its memory limit is killed, and Docker starts it again.

The two are set together: a change replaces both, so name both to keep both.

```sh
openpanel services update web --project shop --cpus 1 --memory 512
```

## Servers [#servers]

The servers the service may run on. Its replicas are spread over them in turn, in a fixed order; see [Replicas](/docs/load-balancing/replicas). The list you send replaces the old one.

A server that has been disconnected stays in the list until you change it, but nothing is placed on it. A service with a volume must keep the server its volume lives on.

## The rules, with their messages [#the-rules-with-their-messages]

A change that breaks a rule is refused, with one of these messages:

| Message | What to do |
|---|---|
| "Turn on the load balancer to run more than one replica of a public service." | Add `--balancer`, or set replicas to 1. |
| "The load balancer is for public services. Make the service public, or turn the load balancer off." | Make it public, or add `--no-balancer`. |
| "A service on a private address runs as one instance." | Set replicas to 1. |
| "This service has a volume, so it always runs as one instance. Remove the volume to use replicas or the load balancer." | See [The single-instance rule](/docs/volumes/single-instance). |
| "Port 80 is listed twice." | List each port once; `http` and `tcp` count as the same transport. |
| "The health check uses port 8080; add it as an HTTP port first." | A health check's port must be one of the service's ports. |
| "Build settings are for a service built from Git." | Leave out `build` for an image. |
| "This service has its own domains. Remove them before taking it off its public address." | Remove its custom domains first. |
| "app.example.com reaches port 80. Remove the domain, or keep that HTTP port." | Keep the port the domain points at, or remove the domain. |
| "The volume at /data lives on a server this change removes. Keep that server in the list." | Keep the volume's server among the service's servers. |

<Cards>
<Card href="/docs/projects/health-checks" title="Health checks" description="How OpenPanel knows a replica is ready." />

<Card href="/docs/volumes" title="Volumes" description="Disk that survives deploys." />
</Cards>