Reading sys.conf fails when built for prod

Hi,

I have a project where I read the configuration file in the xxx_app:start() function.

This is illustrated in a test project at GitLab that is a clean rebar3 umbrella project with the config and a single io:format line added to the skeleton.

It works like a charm if I run the project in developer mode:

$ rebar3 shell 
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling test_config
Erlang/OTP 28 [erts-16.3.1] [source] [64-bit] [smp:32:32] [ds:32:32:10] [async-threads:1] [jit:ns]

*** Reading prometheus config-files: {ok,#{port => 9110}}
===> Booted test_config
===> Booted sasl
Eshell V16.3.1 (press Ctrl+G to abort, type help(). for help)
1> 

But what ever I do I cannot make the config read in a release:

(Paths modified to exclude home folder).

$ rebar3 as prod release
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling test_config
===> Assembling release test_config-0.1.0...
===> Release successfully assembled: _build/prod/rel/test_config
$ cd _build/prod/rel/test_config
_build/prod/rel/test_config $ bin/test_config console
Exec: _build/prod/rel/test_config/erts-16.3.1/bin/erlexec -boot _build/prod/rel/test_config/releases/0.1.0/start -mode embedded -boot_var SYSTEM_LIB_DIR _build/prod/rel/test_config/lib -config _build/prod/rel/test_config/releases/0.1.0/sys.config -args_file _build/prod/rel/test_config/releases/0.1.0/vm.args -- console
Root: _build/prod/rel/test_config
_build/prod/rel/test_config
Erlang/OTP 28 [erts-16.3.1] [source] [64-bit] [smp:32:32] [ds:32:32:10] [async-threads:30] [jit:ns]

*** Reading prometheus config-files: undefined
Eshell V16.3.1 (press Ctrl+G to abort, type help(). for help)
(test_config@localhost)1> 

I just don’t understand what I can possibly get wrong in this single line of code. This should be a simple basic mechanism that “just should work®”.

I use rebar 3.25.1 on Erlang/OTP 28 Erts 16.3.1. I run Gentoo Linux, build erlang locally using kerl, and use version 28.4.2 for this test. I built this release the other day and have not made any updates to my computer since.

In every case I have tested I can open the config in vi using the path shown in the erlexec command.

Your application name is test_config so you should use that name if you sys.config.

Try changing your config to something like:

{test_config, [{prometheus,
                  #{
                      port        => 9110
                  }
              }, ...

and call it like: application:get_env(test_config, prometheus).

Hi,

Wee, thanks.

So the scope I use in the sys.config must apparently match the application name in the app.src file of the application. Wounder why I have to give it then but anyway, it now work.

But anyway, that solved the problem so thanks a lot @WarpEngineer, I have spent almost a day troubleshooting this and remained clueless.

Cheers, Erik

1 Like