Fix data_dir and config_file not reading systemd env vars#1844
Fix data_dir and config_file not reading systemd env vars#1844kickster97 wants to merge 2 commits intomainfrom
Conversation
|
PR Review No issues found. The changes correctly implement systemd environment variable support:
|
src/lavinmq/config/options.cr
Outdated
| @[IniOpt(section: "main")] | ||
| @[EnvOpt("LAVINMQ_DATADIR")] | ||
| property data_dir : String = "/var/lib/lavinmq" | ||
| property data_dir : String = ENV.fetch("STATE_DIRECTORY", "/var/lib/lavinmq") |
There was a problem hiding this comment.
The code looks to support multiple EnvOpt which means you could add
@[EnvOpt("STATE_DIRECTORY")] after the existing EnvOpt and it should pick one of them, the last should have precedence. Have you tested that?
There was a problem hiding this comment.
hm, yeah.. but the thing is that Crystals .annotation() (single) only returns the last annotation, so stacking @[EnvOpt] would silently drop all but the last env var. I'd need to change parse_env to use .annotations() (plural).
That works for data_dir, but config_file has to be resolved before parse_env runs because parse_ini needs the path first, so it still needs special handling. So I end up changing the macro, adding a transform lambda for the directory-to-filepath conversion, and still keeping the early lookup.
What do you think is the downside of the current solution?
There was a problem hiding this comment.
I think it's a tiny change to the code to support multiple EnvOpt.
With the proposed solution in this PR, won't ini config values take precedence over these envs?
There was a problem hiding this comment.
With the proposed solution in this PR, won't ini config values take precedence over these envs?
ah yes thats true, need to fix that!
|
PR Review: No issues found. The changes are clean and well-tested. Precedence chains are correct, the multi-annotation macro change is sound, and the removal of the buggy |
WHAT is this pull request doing?
The config rewrite (#917) replaced the systemd-standard
STATE_DIRECTORYandCONFIGURATION_DIRECTORYenv vars withLAVINMQ_-prefixed variants. Since the systemd unit file (extras/lavinmq.service) declaresStateDirectory=lavinmqandConfigurationDirectory=lavinmq, systemd sets these vars automatically, and they are no longer read.This means anyone using a non-default
StateDirectory= pathin a systemd override will have it silently ignored, falling back to the hardcoded/var/lib/lavinmq. Similarly, a customConfigurationDirectory=in a systemd override would be ignored when resolving the default config file path.This PR restores both systemd env vars as fallbacks.
LAVINMQ_DATADIRandLAVINMQ_CONFIGURATION_DIRECTORYstill take precedence when set.HOW can this pull request be tested?
run added spec