# Services

Keep a web server or a database running on your VM; it restarts after a crash and comes back after every wake.

Source: https://slashinfra.com/docs/platform/services
Last modified: 2026-11-30T16:36:19.000Z

A service is a long-running program on your VM, such as a web server or a database. It comes back after every wake, unless you stopped it, and it starts again when it ends.

The examples use a VM named `api` and a service named `web`. Set `VM` to the VM’s id and `SI_API_KEY` to a key from [API keys](https://app.slashinfra.com/keys):

```bash
export VM=6f1c0f0e8a
export SI_API_KEY=si_...
```

## Add a service

`si svm svc add` writes a definition to `/etc/slashinfra/services/web.json` on the VM’s disk and starts the program as `user`. The definition stays on the disk across a sleep, so the service comes back after a wake.

Inside the VM, the same subcommands are on `svc`; `si svm svc` sends them from your laptop. The VM comes before the command, as in `si svm svc api add web ...`. Without it, `si` uses the VM set with `si use`.

### CLI

```bash
si svm svc api add web --port 3000 --dir /home/user --env PYTHONUNBUFFERED=1 -- python3 -m http.server 3000
```

Output

```text
web
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/svc?arg=add&arg=web&arg=--port&arg=3000&arg=--dir&arg=/home/user&arg=--env&arg=PYTHONUNBUFFERED%3D1&arg=--&arg=python3&arg=-m&arg=http.server&arg=3000" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
web
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/svc",
params=[
("arg", "add"),
("arg", "web"),
("arg", "--port"),
("arg", "3000"),
("arg", "--dir"),
("arg", "/home/user"),
("arg", "--env"),
("arg", "PYTHONUNBUFFERED=1"),
("arg", "--"),
("arg", "python3"),
("arg", "-m"),
("arg", "http.server"),
("arg", "3000"),
],
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
web
```

### TypeScript

```ts
const url = new URL(`https://${process.env.VM!}.slashinfra.dev/usr/bin/svc`)
for (const arg of [
'add',
'web',
'--port',
'3000',
'--dir',
'/home/user',
'--env',
'PYTHONUNBUFFERED=1',
'--',
'python3',
'-m',
'http.server',
'3000',
]) {
url.searchParams.append('arg', arg)
}
const res = await fetch(url, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log((await res.text()).trim())
```

Output

```text
web
```

The words after `--` are the program and its arguments, run without a shell. For a pipeline, a variable or a redirection, use `/bin/bash -c '...'`. The program must stay in the foreground. When its leader ends, the VM ends the rest of its processes and starts it again. A program that should run once belongs in a [job](https://slashinfra.com/docs/platform/commands-and-jobs).

A new service starts within a second.

## Open the port of a service

`--port` names the TCP port the program listens on. A preview at `https://3000-<id>.slashinfra.dev` waits up to 10 seconds while the service is `starting`. A request made during a start can reach the program. The program must listen on `0.0.0.0` or `localhost`.

The port also decides what a sleep keeps. A running service that declares a port is saved in memory and its process resumes after the wake. A service without a port stops for a sleep on disk and starts again after the wake. A service you stopped stays stopped.

To share the address through a link or make it public, open the port. See [Web addresses](https://slashinfra.com/docs/platform/web-addresses).

## List services

The list has one row per definition, by name. `STATE` is the state of the service and `PID` is the process id of the program. `RESTARTS` counts the restarts after a crash, and `PORT` is the declared port or `-`. A service with no process shows `-` in `PID`.

### Dashboard

- Open [SVMs](https://app.slashinfra.com/svms) and select `api`. 
- Select Terminal. A terminal to the VM opens in a new tab. 
- Run the command below. `svc` manages the services of the VM.

```bash
svc ls
```

Output

```text
NAME  STATE  PID  RESTARTS  PORT
web  running  1234  0  3000
```

### CLI

```bash
si svm svc api ls
```

Output

```text
NAME  STATE  PID  RESTARTS  PORT
web  running  1234  0  3000
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/svc?arg=ls" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
NAME  STATE  PID  RESTARTS  PORT
web  running  1234  0  3000
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/svc",
params={"arg": "ls"},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
NAME  STATE  PID  RESTARTS  PORT
web  running  1234  0  3000
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/svc?arg=ls`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log((await res.text()).trim())
```

Output

```text
NAME  STATE  PID  RESTARTS  PORT
web  running  1234  0  3000
```

## Read the log of a service

`svc logs` prints the whole log of a service, standard output and standard error together. The log is `/var/log/services/web.log` on the VM’s disk. It survives a sleep and the deletion of the service. `--follow` keeps printing new lines until you stop it.

### CLI

```bash
si svm svc api logs web
```

Output

```text
Serving HTTP on 0.0.0.0 port 3000 (http://0.0.0.0:3000/) ...
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/svc?arg=logs&arg=web" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
Serving HTTP on 0.0.0.0 port 3000 (http://0.0.0.0:3000/) ...
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/svc",
params=[("arg", "logs"), ("arg", "web")],
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
Serving HTTP on 0.0.0.0 port 3000 (http://0.0.0.0:3000/) ...
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/svc?arg=logs&arg=web`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log((await res.text()).trim())
```

Output

```text
Serving HTTP on 0.0.0.0 port 3000 (http://0.0.0.0:3000/) ...
```

## Stop a service

Stop ends the program and every process it started, then records the stop on the definition. The service stays stopped across a sleep and a wake. The command waits up to 15 seconds for `stopped`; a program that does not end answers with its state.

### CLI

```bash
si svm svc api stop web
```

Output

```text
web stopped
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/svc?arg=stop&arg=web" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
web stopped
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/svc",
params=[("arg", "stop"), ("arg", "web")],
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
web stopped
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/svc?arg=stop&arg=web`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log((await res.text()).trim())
```

Output

```text
web stopped
```

## Start a service

Start clears the stop, starts the program now and starts it again after every wake. A service that already runs keeps its process. The command waits up to 15 seconds for `running`. A service with a port is `running` when the port accepts a connection.

### CLI

```bash
si svm svc api start web
```

Output

```text
web running
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/svc?arg=start&arg=web" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
web running
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/svc",
params=[("arg", "start"), ("arg", "web")],
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
web running
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/svc?arg=start&arg=web`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log((await res.text()).trim())
```

Output

```text
web running
```

## Restart a service

Restart stops the program and starts it again, and resets `RESTARTS` to 0. Use it after you change the program or its files; the definition keeps its flags. The command waits up to 15 seconds for `running`.

### CLI

```bash
si svm svc api restart web
```

Output

```text
web running
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/svc?arg=restart&arg=web" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
web running
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/svc",
params=[("arg", "restart"), ("arg", "web")],
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
web running
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/svc?arg=restart&arg=web`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log((await res.text()).trim())
```

Output

```text
web running
```

## Delete a service

Delete removes the definition and stops the program. The log stays at `/var/log/services/web.log`, and the command waits up to 10 seconds for `stopped`. A service that another definition needs cannot be deleted until you delete that definition.

### CLI

```bash
si svm svc api rm web
```

Output

```text
web removed
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/svc?arg=rm&arg=web" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
web removed
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/svc",
params=[("arg", "rm"), ("arg", "web")],
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
web removed
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/svc?arg=rm&arg=web`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log((await res.text()).trim())
```

Output

```text
web removed
```

## Options

| Field | Type | Default | Allowed values | What it changes |
| --- | --- | --- | --- | --- |   
| `name` (argument) | string | Required | 1 to 64 letters, digits, `-` and `_`, starting with a letter or digit; `daemon` and `units` are reserved | The service name and its definition file. It is unique on the VM. | 
| `port` (`--port`) | integer | None | 1 to 65535 | The TCP port the program listens on. A preview waits while the service is `starting`. | 
| `needs` (`--needs`) | string | None | Names of services of the same VM, as `A,B` | The services that must be `running` before this one starts. | 
| `dir` (`--dir`) | string | `/home/user` | An absolute path | The working directory of the program. | 
| `env` (`--env`) | string | None | `KEY=VALUE`, repeated; the key has letters, digits and `_`, and does not start with `SVM_` | A variable of the service’s process. | 
| `program` (after `--`) | array | Required | A program and its arguments; the first word is searched in `PATH` when it has no `/` | The program to run, without a shell. | 
| `ref` (`<SVM>`) | string | The VM set with `si use` | A VM name, or its id | The VM whose services these are. | 
| `project` (`--project`) | string | `default` | A project name, or its `proj_` id | The project of the VM. `SI_PROJECT` applies when the flag is absent. |

`--needs` accepts only names of services on the same VM. An unknown name, or a cycle, keeps `svc` from applying any change until you add the missing service or delete the definition that names it.

## States

When a program ends without a stop, the VM starts it again after 1 second. The wait then grows to 2, 4, 8, 16 and at most 30 seconds. `RESTARTS` counts the restarts, and the state is `backoff` while the VM waits.

| State | What it means for you | What you can do |
| --- | --- | --- |   
| `running` | The program runs. With a declared port, the port accepts a connection. | Read the log, stop, restart or delete the service. | 
| `starting` | The program runs but its declared port does not accept a connection yet. | Wait; read the log if it stays. A preview waits up to 10 seconds. | 
| `backoff` | The program ended and the VM waits to start it again. `RESTARTS` counts the restarts. | Read the log to find why it ends; fix the program, or stop the service. | 
| `stopped` | No process runs. The definition is stopped, or a service it needs is not `running`. | Start it, or delete it. |

## Errors

| Code | When | Fix |
| --- | --- | --- |   
| [`svm_not_found`](https://slashinfra.com/docs/reference/errors#svm_not_found) | The VM name or id names no VM of your organization or key scope. | Check the name, the id and the project. | 
| [`svm_unreachable`](https://slashinfra.com/docs/reference/errors#svm_unreachable) | The node of the VM did not answer. | Wait for `Retry-After` and retry. | 
| [`not_ready`](https://slashinfra.com/docs/reference/errors#not_ready) | A preview of the declared port waits on a wake and the VM’s readiness port does not answer in its timeout. | Check the log with `si svm svc api logs web`, then retry. |

The VM’s `svc` reports a refused command in the reply. The HTTP status is 200, `X-Exit-Code` is 1, and `si` exits 1. The message names the fix, for example `svc: no service web; svc ls shows the services`, `svc: service web already exists; use svc restart web`, or `svc: web is needed by db; remove it first`.

Errors that any request can return are in the [error catalog](https://slashinfra.com/docs/reference/errors).

## Permissions

Every operation on this page goes to the VM’s own host. A key reaches it when it belongs to the VM’s organization and includes the VM’s project. The VM host checks that scope and does not check a key action. A grant reaches only the methods, paths and arguments it names; see [Grants](https://slashinfra.com/docs/platform/grants).

| Operation | Who can | Key action |
| --- | --- | --- |   
| Add a service | Any member with a key that includes the VM’s project | None | 
| List services | Any member with a key that includes the VM’s project | None | 
| Read the log of a service | Any member with a key that includes the VM’s project | None | 
| Stop a service | Any member with a key that includes the VM’s project | None | 
| Start a service | Any member with a key that includes the VM’s project | None | 
| Restart a service | Any member with a key that includes the VM’s project | None | 
| Delete a service | Any member with a key that includes the VM’s project | None |

## Limits

- A VM has no count limit on services: `svc` starts every definition in `/etc/slashinfra/services` that is not stopped, each in its own cgroup and with its own log. 
- A service name has 1 to 64 letters, digits, `-` and `_`, and starts with a letter or digit. `daemon` and `units` are reserved. 
- `--port` is 1 to 65535. 
- A crash restarts the service after 1 second, then 2, 4, 8, 16 and at most 30 seconds. 
- A stop sends the service’s first signal (SIGTERM by default; the guest `svc add --stop-signal INT` selects SIGINT). It gives the program and its processes 10 seconds, then stops what is left. 
- A preview of a declared port waits up to 10 seconds while the service is `starting`. 
- A running service that declares a port is saved in memory at the memory deadline and resumes after the wake. A service without a port stops for a sleep on disk and starts again after the wake, unless you stopped it. 
- A log rotates when the service starts and the file is at least 10 MiB. It becomes `<name>.log.1`, replacing the previous rotation. 
- A service does not keep the VM awake. A timer or cron job inside the VM does not fire on a sleeping VM. Use a [schedule](https://slashinfra.com/docs/platform/schedules) for work at a set time.

The full list is in [Limits](https://slashinfra.com/docs/reference/limits).

## Next

- [Web addresses](https://slashinfra.com/docs/platform/web-addresses): open the port your service listens on. 
- [Schedules](https://slashinfra.com/docs/platform/schedules): run work at a set time, which a timer inside the VM cannot do. 
- [Sleep and wake](https://slashinfra.com/docs/how/sleep-and-wake): what a VM keeps across a sleep.
