# Starts, stops and restarts

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> Stop a workstation you aren't using, start it again when you need it, and restart it when you want a fresh boot.


Stop a workstation you aren't using, start it again when you need it, and restart it when
you want a fresh boot. A stopped workstation keeps its disk, so it comes back with your
tools, code and files in place. Ringleader can also stop a workstation nobody is using, or
one that has run long enough, with no client running.

## Stopped workstations

A stopped workstation is powered off, and nothing on it is lost: its disk, installed tools
and files stay. It rests in the `Stopped` phase until you start it, then returns to
`Running`. [Workstation phases](https://docs-stg.ringleader.dev/workstations/basics/#workstation-phases)
shows the phases in between.

<div class="callout callout-warning">
  <p class="callout-title">A stopped cloud workstation still costs money</p>
  <div class="callout-body">
    A stopped cloud workstation still costs money for its disk, as
<a href="https://docs-stg.ringleader.dev/organizations-teams/usage-cost/#hour-buckets">Hour buckets</a> explains. To
remove the disk too, delete the workstation, as
<a href="https://docs-stg.ringleader.dev/workstations/lifecycle/deletion-deadlines/">Deletion and delete deadlines</a>
describes.
  </div>
</div>


A workstation's `status.stopCause` says why it's stopped, whether its idle policy, its run
limit, or a [running, vCPU or GPU cap](https://docs-stg.ringleader.dev/organizations-teams/accounts-access/namespaces-limits/#running-limits).
[Status fields](https://docs-stg.ringleader.dev/reference/resources/workstation/#status-fields) lists it.
[Idle stop](#idle-stop) and [Maximum run time](#maximum-run-time) cover the stops Ringleader
makes.

## Workstation restarts

A restart powers the workstation off and on again. It's a real power cycle, not a reload of
the configuration, so it clears in-memory state. A restart of a stopped workstation starts
it.

When one `rl workstation restart` command names several workstations, or a label selector
that matches several, they all share one restart. Each new run of the command restarts them
again.

## State reset by a stop or start

Some of what a workstation reports belongs to the boot that produced it. A stop or a start
clears it:

- The record of the configuration the workstation applied. A stop empties `status.config.appliedHash` and sets the
  `Configured` condition to `False`, so a stopped workstation never claims a configuration
  from an earlier boot. After a start, `Configured` turns `True` again once the in-VM agent
  reports the current configuration.
- The result of a job. `Finished` turns `False`, as
  [Jobs and their results](https://docs-stg.ringleader.dev/workstations/lifecycle/jobs-results/)
  describes.
- The idle clock, `status.idleSince`. An [idle policy](#idle-stop) counts again from the start.
- The run limit. A start begins a new run, so
  [`lifecycle.maxRunTime`](#maximum-run-time)
  counts from the start.

## Stops in a workstation file

Whether a workstation is stopped is a field in its description, `spec.stopped`.
`rl workstation stop`, the application, the terminal UI and Ringleader's own automatic stops
all set it to `true`. A restart writes a new value to `spec.restartNonce`, with
`stopped: false`. A start writes one too when the workstation is marked running but is down.

Applying a file over a field that a command set overrides the command. `rl apply` warns
first, as
[Fields a command owns](https://docs-stg.ringleader.dev/reference/cli/commands/resource-verbs/#fields-a-command-owns)
describes.

## Automatic stops

A workstation nobody turned off keeps costing money. Automatic stops cover a CI job that
was killed outright, or a workstation you meant to keep for an afternoon. You set them in
`spec.lifecycle`. You set stops and a delete deadline there, and they combine. The
[Deletion deadline](https://docs-stg.ringleader.dev/workstations/lifecycle/deletion-deadlines/#deletion-deadline)
section of the Deletion page describes the last line:

```yaml
spec:
  lifecycle:
    idle:
      timeout: 30m         # stop after 30 minutes with nobody using it
      action: stop         # optional, and the only allowed value
      sshSessions: true    # an SSH session means somebody is using it
    maxRunTime: 8h         # stop once this run has lasted 8 hours
    ttl: 7d                # delete a week after it was created
```

## Idle stop

An idle policy stops a workstation after a period in which nothing you named as activity
happened. You name the activity with one or more conditions. A condition can be an SSH
session, a running process, a connection to a port, or a command of your own. A check inside
the workstation reports what it sees, and Ringleader decides when to stop it.

Every condition you declare must agree that the workstation is idle before the timeout
starts, so each condition you add makes a stop less likely. A timeout with no condition is
rejected, and so is a condition with no timeout. `action` is optional, and `stop` is the only
value. To have a workstation deleted, give it a delete deadline instead.

A workstation that reported itself idle and then went quiet keeps its last report and its
clock, so the timeout still runs out. The clock is `status.idleSince`, which
[Status fields](https://docs-stg.ringleader.dev/reference/resources/workstation/#status-fields) describes.
[Lifecycle block fields](https://docs-stg.ringleader.dev/reference/resources/workstation/#lifecycle-block-fields)
lists what each condition counts.

## Maximum run time

`lifecycle.maxRunTime` stops a workstation once its current run has lasted that long,
whatever is happening on it. The clock starts when the workstation starts, not when it was
created. So a workstation that stops in the evening can be started the next morning for a
new run. Its status message names the field that stopped it, and tells you to start the
workstation to begin another run.

`ttlAction: stop` is the older spelling of `maxRunTime`: it stops the workstation instead of
deleting it, and counts from the start of the current run. A workstation can't declare both
`maxRunTime` and `ttlAction: stop`.

## Deadline enforcement

Ringleader checks the deadlines periodically, so a workstation can run briefly past its
deadline before Ringleader stops or deletes it. Treat a deadline as "at this time or shortly
after".

The next deadline, whether it stops or deletes the workstation, is its `status.expiresAt`,
which [Status fields](https://docs-stg.ringleader.dev/reference/resources/workstation/#status-fields) lists.

## Lifetimes on a WorkstationConfig

`lifecycle`, which holds `ttl`, and `ttlAction` are Workstation fields only, and `rl apply` rejects them on a
[WorkstationConfig](https://docs-stg.ringleader.dev/reference/resources/workstationconfig/). A WorkstationConfig
can attach by label to workstations its author doesn't own, so a lifetime there could stop
them. Set the lifetime on each workstation that needs one.

## Stop or start a workstation

To stop a workstation, click its card's stop button in the application, or run:

```bash
rl workstation stop my-box -n local
```

To start it again, click the start button, or run:

```bash
rl workstation start my-box -n local
```

In the terminal UI, select the workstation and press `s` to stop it or `S` to start it, as
[Resource management](https://docs-stg.ringleader.dev/reference/tui/resource-management/) shows.

Each command returns once Ringleader accepts the request, and the workstation then changes
state. A cloud workstation takes about a minute to start. To wait until the change is done,
add `--wait`.

To stop or start several workstations at once, name them all, or pass a label selector with
`-l`. [`rl workstation start` / `stop` / `restart`](https://docs-stg.ringleader.dev/reference/cli/commands/workstation-access/#rl-workstation-start--stop--restart)
lists the flags.

## Stop or start a workstation from its file

To keep a workstation stopped in its file, set `stopped: true` and apply the file:

```yaml
spec:
  stopped: true
```

To start it, set `stopped: false`, or remove the line, and apply the file again.

## Restart a workstation

To restart a workstation, click **Restart** on its open card in the application, or run:

```bash
rl workstation restart my-box -n local
```

Add `--wait` to wait until the workstation is `Ready` again.

To restart a workstation from its file, change `spec.restartNonce` to any new value and
apply the file. Only the change matters, not the value:

```yaml
spec:
  restartNonce: "2"
```

## Start a workstation when you connect

To start a stopped workstation as you connect to it, add `--start` to `rl shell` or
`rl tmux`:

```bash
rl shell --start my-box -n local -- make test
```

`rl shell` asks Ringleader to start the workstation, waits until it's `Ready`, then
connects. If the workstation is already starting, it waits for it. If it's already running,
it connects at once.

If the workstation can't start, `--start` prints one line that says why, and doesn't
connect. That happens in two cases:

- The workstation is being deleted.
- The workstation is in the `Failed` phase and nothing is retrying it. The line then names
  what will move it, such as `rl workstation restart`.

If the [maximum run time](#maximum-run-time)
stopped the workstation, `--start` starts it for a new run. In the terminal UI, `Enter` and
`t` on a stopped workstation offer to start it first.

## Stop a workstation when it's idle

To stop a workstation after 45 minutes with no SSH session and no `pytest` running, add an
idle policy to its file and apply it:

```yaml
spec:
  lifecycle:
    idle:
      timeout: 45m
      action: stop
      sshSessions: true
      processes: ["pytest"]
```

[Lifecycle block fields](https://docs-stg.ringleader.dev/reference/resources/workstation/#lifecycle-block-fields)
gives the rules for process names and durations.

## Limit how long a workstation runs

To stop a workstation after 8 hours of running, whatever it's doing, set `maxRunTime`:

```yaml
spec:
  lifecycle:
    maxRunTime: 8h
```

To run it again, start it, as
[Stop or start a workstation](#stop-or-start-a-workstation)
shows. The new run gets the full 8 hours.

## Check when a workstation stops

Run `rl workstation get`. When any workstation in the list declares a deadline, the output
has an **EXPIRES** column, which counts down or reads `expired`. The column shows the next
deadline, whether it stops or deletes the workstation:

```bash
rl workstation get -n local
```

In the application, an open card's **Deadline** line names the next deadline, and its
**Idle for** line says how long the workstation has been idle. To see why a workstation
stopped, read its `stopCause`:

```bash
rl workstation get my-box -n local -o jsonpath='{.status.stopCause}'
```

## Next steps

- [Deletion and delete deadlines](https://docs-stg.ringleader.dev/workstations/lifecycle/deletion-deadlines/)
  removes a workstation and its disk, now or at a deadline.
- [`rl workstation start` / `stop` / `restart`](https://docs-stg.ringleader.dev/reference/cli/commands/workstation-access/#rl-workstation-start--stop--restart)
  lists every flag of the three commands.

