Repository navigation
fix(systemd): read WORKERS in the REST unit - #237
PromiseFru merged 2 commits into
Conversation
relaysms-publisher-rest.service hard-coded --workers 4, while
scripts/run.sh and the Docker entrypoint read WORKERS from the
environment, so setting WORKERS in .env had no effect on server installs.
systemd's ExecStart= supports ${VAR} but not shell-style ${VAR:-4}, so
the unit sets Environment=WORKERS=4 as the default and passes
--workers "${WORKERS}". EnvironmentFile= overrides Environment=, so a
WORKERS line in .env takes precedence.
Adds a render_units test and notes in the settings reference that all
three launchers read WORKERS from .env.
Fixes smswithoutborders#221
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FiGQujBCL8qnuH6bAv3Yiz
PromiseFru
left a comment
There was a problem hiding this comment.
Thank you, the fix and the test look right. A few suggestions below.
| # Default worker count. EnvironmentFile= overrides Environment=, so WORKERS | ||
| # in .env wins. systemd has no ${VAR:-default} syntax, hence this line. |
There was a problem hiding this comment.
The comment only needs to say when the line applies. The rest argues for the design.
| # Default worker count. EnvironmentFile= overrides Environment=, so WORKERS | |
| # in .env wins. systemd has no ${VAR:-default} syntax, hence this line. | |
| # Used when .env doesn't set WORKERS. |
| # EnvironmentFile= overrides Environment=, so WORKERS in .env wins | ||
| # over this default. |
There was a problem hiding this comment.
This repeats the unit's comment, and none of the assertions check the override it describes.
| # EnvironmentFile= overrides Environment=, so WORKERS in .env wins | |
| # over this default. |
| # 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") |
There was a problem hiding this comment.
EnvironmentFile= was already in the unit, so this passes with or without the fix.
| assert unit_values(rest, "EnvironmentFile") |
| | `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`. | |
There was a problem hiding this comment.
The page intro already says settings live in .env.
| | `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`. | | |
| | `WORKERS` | None | REST API worker processes: `1` by default under `scripts/run.sh`, `4` on Docker and server installs | |
Shorten the unit comment to when the default applies, drop the test comment and the EnvironmentFile assertion that passed without the fix, and restore the WORKERS row in the settings reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FiGQuixu9idHjQGyTk9VMQ
|
Thanks for the review! Done in 3851fb6: shortened the unit comment to "Used when .env doesn't set WORKERS.", dropped the test comment and the |
PromiseFru
left a comment
There was a problem hiding this comment.
Thank you, this looks good!
Fixes #221
Supersedes #234, which targeted
mainby mistake.relaysms-publisher-rest.servicehard-coded--workers 4, whilescripts/run.shand the Docker entrypoint readWORKERS, so setting it in.envhad no effect on server installs.Changes
Environment=WORKERS=4as the default and passes--workers "${WORKERS}".--workers "${WORKERS:-4}", butExecStart=only supports${VAR}/$VARsubstitution, not shell-style defaults (systemd.service). SinceEnvironmentFile=overridesEnvironment=(systemd.exec),WORKERSin.envstill wins.tests/scripts/test_lib.py:test_rest_unit_reads_workers_with_a_defaultchecks the rendered unit. It fails against the old unit.docs/configuration/settings.md: theWORKERSrow notes that all three launchers read it from.env.Checks
make checkhooks run locally on the changed files: trailing-whitespace, end-of-file, ruff check/format, shellcheck, import-linter, pyright (0 errors in the changed files; the only repo-wide errors are the unbuiltlib_relaysms_payload_specs.generatedmodule) and commitizen pass. shfmt, dockerfmt and dclint could not be installed in my environment (no Go/Node download).shfmt -i 2 -dfrom shfmt-py reports no changes.pytest tests/test_config.py tests/scripts/test_lib.py: 62 passed, run with a stub for the Rust-builtlib_relaysms_payload_specs.generatedmodule (not touched here).systemd-analyze verifyaccepts the rendered unit. Not started under a live systemd;make test-e2e(Podman) not run.WORKERS=line left empty in.envwould override the default with an empty value, asHOST/PORTwould today.template.envships it commented out.🤖 Generated with Claude Code
https://claude.ai/code/session_01FiGQujBCL8qnuH6bAv3Yiz