[erlang-questions] REPLACE_OS_VARS in erlexec?

Dave Cottlehuber dch@REDACTED
Thu Mar 30 23:50:12 CEST 2017


On Wed, 29 Mar 2017, at 21:55, Stefan Hellkvist wrote:
> Hello Erlangers,
> 
> For different reasons (for instance to be able to run distributed Erlang
> inside Kubernetes for instance, like here:
> https://substance.brpx.com/clustering-elixir-nodes-on-kubernetes-e85d0c26b0cf),
> there is a need to be able to override or replace the settings in vm.args
> (or the args_file if you use the name of the argument to erlexec) with
> environment variables.
> 
> For instance like so (example taken from the above article):
> 
> ----begin vm.args----
> ## Name of the node
> -name ${MY_POD_NAMESPACE}@${MY_POD_IP}
> 
> ## Cookie for distributed erlang
> -setcookie ${ERLANG_COOKIE}
> ...
> ----end vm.args-----
> 
> 
> The need for this functionality seems to be big enough for there to now
> be
> support for it in the release builders (relx for instance offers a way to
> turn on vm.args environment variable replacement with the
> RELX_REPLACE_OS_VARS environment variable when running the start script).
> 
> 
> My question though is if this functionality (to set variables such as
> -name
> or -setcookie in args_file through environment variables) has ever been
> considered for erlexec itself?
> 
> For various reasons (mostly to reduce dependencies to other programs such
> as various shell utilities) I would like to start my erlang nodes without
> the generated release script by calling erlexec directly, but I realize I
> would, by doing so, miss out on the power to set variables in arg-file
> with
> environment variables (like in relx above).
> 
> I guess it would not be extremely difficult to modify erlexec for this
> purpose (erlexec already has functions for reading environment variables
> so
> it would be a small change I guess) but I'm not sure if there would be
> enough interest in this feature to accept a pull-request and I would not
> like to roll my own fork of OTP only for this rather limited purpose. So,
> does anyone know if this this feature has ever been discussed or
> considered
> for inclusion in OTP?
> 
> /Stefan

Sounds very useful. I have at least a couple of times removed all the
release script cruft and written a simple erlexec wrapper, for debugging
purposes.  I assume using erlexec directly is not supported as I don't
find it in the usual place like http://erlang.org/doc/man/erl.html

My main gripe with relx and descendants is that simply replacing
variables and creating a new vm.args file is a horrible hack. It would
be nice to have that support built into the emulator directly, as you
propose. 

BTW my latest version of this (with Elixir goodness) is here: -
https://gist.github.com/dch/aee49d986e6acf7621c0b48366dab727
and you can pass arbitrary parameters to erlexec, such as -env KEY
VALUE, -setcookie ... and -[s]name .... (in fact any other parameter
that erl accepts) directly, but I suppose you already know this.

A+
Dave



More information about the erlang-questions mailing list