diff --git a/deploy/systemd/relaysms-publisher-rest.service b/deploy/systemd/relaysms-publisher-rest.service index ba34b62..1342618 100644 --- a/deploy/systemd/relaysms-publisher-rest.service +++ b/deploy/systemd/relaysms-publisher-rest.service @@ -10,12 +10,14 @@ StartLimitBurst=5 Type=simple User=relaysms WorkingDirectory=/opt/relaysms/relaysms-publisher +# Used when .env doesn't set WORKERS. +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 diff --git a/tests/scripts/test_lib.py b/tests/scripts/test_lib.py index 36aea53..7fcd95f 100644 --- a/tests/scripts/test_lib.py +++ b/tests/scripts/test_lib.py @@ -132,6 +132,13 @@ 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"] + + assert unit_values(rest, "Environment").count("WORKERS=4") == 1 + (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")