Skip to content

fix(systemd): read WORKERS in the REST unit - #237

Merged
PromiseFru merged 2 commits into
smswithoutborders:stagingfrom
tomahawkeer:fix/systemd-rest-workers-env
Nov 4, 2026
Merged

PromiseFru merged 2 commits into
smswithoutborders:stagingfrom
tomahawkeer:fix/systemd-rest-workers-env

Conversation

@tomahawkeer

Copy link
Copy Markdown
Contributor

Fixes #221
Supersedes #234, which targeted main by mistake.

relaysms-publisher-rest.service hard-coded --workers 4, while scripts/run.sh and the Docker entrypoint read WORKERS, so setting it in .env had no effect on server installs.

Changes

  • The unit sets Environment=WORKERS=4 as the default and passes --workers "${WORKERS}".
    • The issue suggested --workers "${WORKERS:-4}", but ExecStart= only supports ${VAR} / $VAR substitution, not shell-style defaults (systemd.service). Since EnvironmentFile= overrides Environment= (systemd.exec), WORKERS in .env still wins.
  • tests/scripts/test_lib.py: test_rest_unit_reads_workers_with_a_default checks the rendered unit. It fails against the old unit.
  • docs/configuration/settings.md: the WORKERS row notes that all three launchers read it from .env.

Checks

  • make check hooks 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 unbuilt lib_relaysms_payload_specs.generated module) and commitizen pass. shfmt, dockerfmt and dclint could not be installed in my environment (no Go/Node download). shfmt -i 2 -d from shfmt-py reports no changes.
  • pytest tests/test_config.py tests/scripts/test_lib.py: 62 passed, run with a stub for the Rust-built lib_relaysms_payload_specs.generated module (not touched here).
  • systemd-analyze verify accepts the rendered unit. Not started under a live systemd; make test-e2e (Podman) not run.
  • Note: a WORKERS= line left empty in .env would override the default with an empty value, as HOST/PORT would today. template.env ships it commented out.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FiGQujBCL8qnuH6bAv3Yiz

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 PromiseFru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, the fix and the test look right. A few suggestions below.

Comment on lines +13 to +14
# Default worker count. EnvironmentFile= overrides Environment=, so WORKERS
# in .env wins. systemd has no ${VAR:-default} syntax, hence this line.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment only needs to say when the line applies. The rest argues for the design.

Suggested change
# 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.

Comment thread tests/scripts/test_lib.py Outdated
Comment on lines +138 to +139
# EnvironmentFile= overrides Environment=, so WORKERS in .env wins
# over this default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeats the unit's comment, and none of the assertions check the override it describes.

Suggested change
# EnvironmentFile= overrides Environment=, so WORKERS in .env wins
# over this default.

Comment thread tests/scripts/test_lib.py Outdated
# 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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvironmentFile= was already in the unit, so this passes with or without the fix.

Suggested change
assert unit_values(rest, "EnvironmentFile")

Comment thread docs/configuration/settings.md Outdated
| `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`. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page intro already says settings live in .env.

Suggested change
| `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
@tomahawkeer

Copy link
Copy Markdown
Contributor Author

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 EnvironmentFile assertion (you're right, it passed without the fix), and reverted the settings.md row. 62 tests still pass, and the test still fails against the old unit.

@PromiseFru PromiseFru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks good!

@PromiseFru
PromiseFru merged commit d2ace24 into smswithoutborders:staging Nov 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants