0

I'm unable to get my application to read an environment variable set on Ubuntu. I keep getting the message below:

** (ArgumentError) could not fetch environment variable "VARIABLE" because it is not set

This is what I have in my prod.exs variable: System.get_env("VARIABLE") || "${VARIABLE}"

I then try to run my application as below

RELX_REPLACE_OS_VARS=true /home/app/prod/rel/my_app/bin/my_app start

I've looked everywhere but tutorials either seem mostly to lean towards Phoenix which I do not have in my application or using an additional dependency which I am not too inclined to do.

Masinde Muliro
  • 1,175
  • 3
  • 24
  • 38
  • this should help: https://stackoverflow.com/questions/58815793/cant-start-a-elixir-phoenix-as-a-mix-release/58816356#58816356 – Daniel Apr 21 '20 at 18:44
  • No joy! I'd tried this ealier. I get the error below: `{"init terminating in do_boot",{undef,[{'Elixir.System','get_env!',[<<"VARIABLE">>],[]},{erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,680}]}` – Masinde Muliro Apr 21 '20 at 19:00
  • that should work for sure, check your elixir version, runtime configs are available since 1.9 – Daniel Apr 21 '20 at 21:21
  • 1
    I'm not familiar with `RELX_REPLACE_OS_VARS`, but have you tried something as simple as setting the ENV var when you run the command? E.g. `VARIABLE=something /home/app/prod/rel/my_app/bin/my_app start` ? It sounds like you could be running into the problems with trying to read ENVs at _runtime_ when they were read (and persisted) at _compile-time_. – Everett Apr 21 '20 at 21:34
  • if you have a runtime configuration, the compile-time one gets overwritten. – Daniel Apr 21 '20 at 22:06
  • Which version of elixir ar you using? Are you using distillery? In which file are you reading the variable? – Adam Millerchip Apr 21 '20 at 22:39
  • I'm using elixir version 1.9.2. I've since removed these lines `RELX_REPLACE_OS_VARS=true` and trying to use mix releases. The environment variable can be seen when you `printenv` but not replaced at start as documentation says of anything placed in `releases.exs` – Masinde Muliro Apr 22 '20 at 04:25

0 Answers0