# amoorion.daemon.base

Daemon: runs services side by side until one ends or it is stopped.

A service is anything long-running: the API (which also receives the hooks)
and a NATS subscriber now; platform listeners (Discord, Telegram, Matrix
bots) later. When one service ends or fails, the others are stopped.

### Functions

| [`serve`](#amoorion.daemon.base.serve)(args)          | Run the daemon until stopped: `amoorion daemon`.   |
|-----------------------------------------------------------------------|----------------------------------------------------|
| [`services`](#amoorion.daemon.base.services)(host, port) | The API always; NATS when `.env` names its server. |

### Classes

| [`ApiService`](#amoorion.daemon.base.ApiService)(host, port)   | The HTTP API with its hooks, as a service of the daemon.    |
|---------------------------------------------------------------------------|-------------------------------------------------------------|
| [`Daemon`](#amoorion.daemon.base.Daemon)(services)         | Runs the services together; when one ends, all are stopped. |
| [`Service`](#amoorion.daemon.base.Service)([view])          | One long-running part of the daemon.                        |

### *class* amoorion.daemon.base.Service(view=None)

Bases: [`Controller`](amoorion.core.html.md#amoorion.core.Controller)

One long-running part of the daemon. It runs until stopped; see `Daemon`.

* **Parameters:**
  **view** ([*View*](amoorion.core.html.md#amoorion.core.View) *|* *None*)

#### *async* run()

Work until stopped; returning or raising ends the whole daemon.

* **Return type:**
  None

#### *async* stop()

Ask the service to end; `run` should return soon after.

* **Return type:**
  None

### *class* amoorion.daemon.base.ApiService(host, port)

Bases: [`Service`](#amoorion.daemon.base.Service)

The HTTP API with its hooks, as a service of the daemon.

* **Parameters:**
  * **host** (*str*)
  * **port** (*int*)

#### *async* run()

Serve until `stop` is called.

* **Return type:**
  None

#### *async* stop()

Ask the server to finish what it is doing and exit.

* **Return type:**
  None

### *class* amoorion.daemon.base.Daemon(services)

Bases: [`Controller`](amoorion.core.html.md#amoorion.core.Controller)

Runs the services together; when one ends, all are stopped.

A half-working daemon is worse than a stopped one, as something restarts it from
outside (systemd, a container).

* **Parameters:**
  **services** (*list* *[*[*Service*](#amoorion.daemon.base.Service) *]*)

#### *async* run()

Start every service, wait for the first to end, stop the rest, raise its failure if any.

* **Return type:**
  None

### amoorion.daemon.base.services(host, port)

The API always; NATS when `.env` names its server.

* **Parameters:**
  * **host** (*str*)
  * **port** (*int*)
* **Return type:**
  list[[*Service*](#amoorion.daemon.base.Service)]

### amoorion.daemon.base.serve(args)

Run the daemon until stopped: `amoorion daemon`.

* **Parameters:**
  **args** (*Namespace*)
* **Return type:**
  None
