Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AnneCYH committed Jul 25, 2024
1 parent 4283773 commit 186a469
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions docs/how-to/service-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ We are using Python's http module to mock the servers.
```
### Problem with setup

If we start the Pebble daemon (``pebble run``):
If we start the Pebble daemon (`pebble run`):

```{terminal}
:input: pebble run
Expand All @@ -75,7 +75,7 @@ If we start the Pebble daemon (``pebble run``):
```

Ideally we would expect all three services to start up successfully
(``pebble services``):
(`pebble services`):

```{terminal}
:input: pebble services
Expand All @@ -88,8 +88,8 @@ frontend enabled active today at 10:17 CST

However, this configuration does not account for the service dependencies.

For example, the output below shows the ``database`` service failing to start
("inactive"), but the ``backend`` and ``frontend`` services starting
For example, the output below shows the `database` service failing to start
("inactive"), but the `backend` and `frontend` services starting
successfully ("active"):

```{terminal}
Expand Down Expand Up @@ -120,8 +120,8 @@ resources unnecessarily.

## Define service dependencies

To create service dependencies in Pebble, use the ``requires`` key with
``before`` / ``after`` in the
To create service dependencies in Pebble, use the `requires` key with
`before` / `after` in the
[service definition](../reference/layer-specification.md).

### Specify dependent services
Expand Down Expand Up @@ -151,14 +151,14 @@ services:
startup: enabled
```

In the layer configuration above, the ``backend`` service is dependent on the
``database`` service, and the ``frontend`` service is dependent on the
``backend`` service.
In the layer configuration above, the `frontend` service is dependent on the
`backend` service, and the `backend` service is dependent on the `database`
service.

### Specify start order for dependent services

To specify the order in which one or more dependent services must start
successfully, relative to a given service, use the ``before`` or ``after`` keys.
successfully, relative to a given service, use the `before` or `after` keys.

```{code-block} yaml
:emphasize-lines: 8, 9, 16, 17
Expand Down Expand Up @@ -186,17 +186,17 @@ services:
startup: enabled
```

In the updated layer above, the ``backend`` service requires the ``database``
service to be started before it, and the ``frontend`` service requires the
``backend`` service to be started before it.
In the updated layer above, the `frontend` service requires the `backend`
service to be started before it, and the `backend` service requires the
`database` service to be started before it.

```{note}
Currently, ``before`` and ``after`` are of limited usefulness, because Pebble only waits 1 second before moving on to start the next service, with no additional checks that the previous service is operating correctly.
Currently, `before` and `after` are of limited usefulness, because Pebble only waits 1 second before moving on to start the next service, with no additional checks that the previous service is operating correctly.
If the configuration of `requires`, `before`, and `after` for a service results in a cycle or "loop", an error will be returned when attempting to start or stop the service.
```

% Does it only check that the status is "Active"? So what does `require` do?
% Does it only check that the status is "Active"? So what does `requires` do?

## Verify service dependencies

Expand All @@ -215,8 +215,8 @@ To verify the start order of services, start the Pebble daemon again:
2024-06-28T03:53:26.338Z [pebble] Started default services with change 1.
```

The start order is now ``database`` -> ``backend`` -> ``frontend`` and all
services are "active".
The start order is now `database` -> `backend` -> `frontend` and all services
are "active".

```{terminal}
:input: pebble services
Expand All @@ -227,16 +227,17 @@ database enabled active today at 10:17 CST
frontend enabled active today at 10:17 CST
```

To further verify the service dependencies, we can force fail a service that is
required by another service.
For example, if we force the ``database`` service to fail, the output for the
``pebble run`` command should be similar to:
To further verify the service dependencies, we force a service that is required
by another service to fail.

In this example, if we force the `database` service to fail (by using port 3306
for another process), the output for the `pebble run` command should be similar
to:

```{terminal}
:input: pebble run
2024-06-28T02:28:06.569Z [pebble] Started daemon.
[database backend frontend]
2024-06-28T02:28:06.575Z [pebble] POST /v1/services 3.212375ms 202
2024-06-28T02:28:06.578Z [pebble] Service "database" starting: python3 -m http.server 3306
2024-06-28T02:28:06.627Z [pebble] Change 1 task (Start service "database") failed: cannot start service: exited quickly with code 1
Expand Down Expand Up @@ -267,4 +268,4 @@ failed run.
- [Changes and tasks](../reference/changes-and-tasks/changes-and-tasks.md)
- [Layer specification](../reference/layer-specification.md)

[Changes and tasks]: /reference/changes-and-tasks/changes-and-tasks.md
[Changes and tasks]: /reference/changes-and-tasks/changes-and-tasks.md

0 comments on commit 186a469

Please sign in to comment.