Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion deploy/systemd/relaysms-publisher-rest.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ StartLimitBurst=5
Type=simple
User=relaysms
WorkingDirectory=/opt/relaysms/relaysms-publisher
# Default worker count. EnvironmentFile= overrides Environment=, so WORKERS
# in .env wins. systemd has no ${VAR:-default} syntax, hence this line.
Environment=WORKERS=4
EnvironmentFile=/opt/relaysms/relaysms-publisher/.env
Environment=OTEL_SERVICE_NAME=relaysms-publisher-rest
Environment=PATH=/opt/relaysms/relaysms-publisher/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Fails the unit on a config error before uvicorn starts its workers.
ExecStartPre=/opt/relaysms/relaysms-publisher/venv/bin/python3 -c "import publisher.api.rest.app"
ExecStart=/opt/relaysms/relaysms-publisher/scripts/otel-wrap.sh /opt/relaysms/relaysms-publisher/venv/bin/python3 -m uvicorn publisher.api.rest.app:app --host "${HOST}" --port "${PORT}" --workers 4 --proxy-headers --forwarded-allow-ips "*"
ExecStart=/opt/relaysms/relaysms-publisher/scripts/otel-wrap.sh /opt/relaysms/relaysms-publisher/venv/bin/python3 -m uvicorn publisher.api.rest.app:app --host "${HOST}" --port "${PORT}" --workers "${WORKERS}" --proxy-headers --forwarded-allow-ips "*"
Restart=on-failure
RestartSec=5
SyslogIdentifier=relaysms-publisher-rest
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Settings live in `.env` in the install directory. `template.env` lists each one
| --- | --- | --- |
| `HOST` | `127.0.0.1` | REST API address. Docker always binds `0.0.0.0`. |
| `PORT` | `16000` | REST API port |
| `WORKERS` | None | REST API worker processes: `1` by default under `scripts/run.sh`, `4` on Docker and server installs |
| `WORKERS` | None | REST API worker processes: `1` by default under `scripts/run.sh`, `4` on Docker and server installs. All three read it from `.env`. |
| `GRPC_HOST` | `127.0.0.1` | gRPC address. Docker always binds `0.0.0.0`. |
| `GRPC_PORT` | `6000` | gRPC port |
| `GRPC_MAX_WORKERS` | `10` | gRPC worker threads |
Expand Down
10 changes: 10 additions & 0 deletions tests/scripts/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ def test_renders_every_unit_for_this_install(self, install, bash):
assert unit_values(rest, "ReadWritePaths") == [" ".join(app_directories(bash))]
assert "/opt/relaysms" not in "".join(units.values())

def test_rest_unit_reads_workers_with_a_default(self, install, bash):
rest = self.render(install, bash)["relaysms-publisher-rest.service"]

# EnvironmentFile= overrides Environment=, so WORKERS in .env wins
# over this default.
assert unit_values(rest, "Environment").count("WORKERS=4") == 1
assert unit_values(rest, "EnvironmentFile")
(exec_start,) = unit_values(rest, "ExecStart")
assert '--workers "${WORKERS}"' in exec_start

def test_named_instance_renames_units_and_references(self, bash, install):
units = self.render(install, bash, INSTANCE_NAME="acme")

Expand Down