New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing directories as the config sources #257
Conversation
We should allow passing the entire directories as the config sources. In this case CouchDB will traverse the given directories and load every *.ini file found. E.g. "... -couch_ini /etc/couchdb/default.d/ /etc/couchdb/local.d/ /path/to/extra/couchdb/default.ini /path/to/extra/couchdb/local.ini ..." Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
LGFM. +1. It was fun to consume php configs on start (: |
Ah, I was a bit in rush: if directory is specified with trailing slash it will not be handled correctly: the Better replace: |
@kxepal quite the contrary - it wil be handled correctly in any way. However I agree - that will be a source of confusion for further CouchDB code divers. |
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
I'm confused. couchdb already loads all .ini files in the default.d and local.d directories. What is this adding? |
lists:foldl( | ||
fun (V, AccIn) -> | ||
case file:read_file_info(V) of | ||
{ok, #file_info{type = regular}} -> AccIn ++ [V]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be [V | AccIn]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(reverse at the end if the order mattered)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order matters since otherwise we'll write all the changes to the first config in chain and it is default.ini.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, just saying it's conventional to prepend then lists:reverse at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, use lists:foldr/3 and just do [V | AccIn] without the reverse.
finally, this area of code changes quite a bit after the 1843-feature-bigcouch merge. |
fun (V, AccIn) -> | ||
case file:read_file_info(V) of | ||
{ok, #file_info{type = regular}} -> AccIn ++ [V]; | ||
{ok, #file_info{type = directory}} -> AccIn ++ filelib:wildcard(filename:join([V,"*.ini"])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in IRC, the ordering of filelib:wildcard is not specified, so this is unpredictable.
To fix this, let's have [V | AccIn] for the earlier clause, preserve this clause, but add a final lists:sort(Values) for the function's result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to adding a sort.
my thoughts captured here: https://github.com/rnewson/couchdb/compare/erlang-expand?expand=1 |
@rnewson
The above patch applied on top of your patch confirms that default.ini is first.
Yet default.ini is somehow the file that is written to.
|
I was partially wrong ...
couchdb does try to write to the first ini during startup.
When you try to save a configuration via REST it does write to the last ini, so @rnewson's patch actually does work. Any idea where/why it opens the first ini file for writing during startup? |
Also, this should be ported to the couchdb-config app since this won't merge to master. Should be a trivial move though. |
This PR was reworked, and applied upstream as apache/couchdb-config#9. Time to close this one. Thanks everyone! |
We should allow passing the entire directories as the config sources. In
this case CouchDB will traverse the given directories and load every
*.ini file found.
E.g.
"... -couch_ini /etc/couchdb/default.d/ /etc/couchdb/local.d/ /path/to/extra/couchdb/default.ini /path/to/extra/couchdb/local.ini ..."
Signed-off-by: Peter Lemenkov lemenkov@gmail.com