Erlang release app passing command line parameters

Hello.

I’ve searched now a bit for this in various places. Supposedly it should work with escript.
My rebar3 project, when I tell it to create a ‘release’, it seems to create some scripts that allow to start the application. In particular with specifying {extended_start_script, true} I get many options. But it’s not clear to me what I have to do to allow passing arbitrary parameters and make the application start as daemon, since it is a server application.
Any advice would be welcome.

Manfred

3 Likes

Hello Manfred,

I am not an Erlang Guru but for me it works for LINUX as follows:

Lets assume the name of the project is: wf
rebar3 as prod release
is generating a shell script wf in
wf/_build/prod/rel/wf/bin

with
./wf daemon
you may start this application in the background.
If you like to start it from system V write a
a script for example
wfstart

in

/etc/init.d

This script may contain beneath others:

export RUN_ERL_LOG_GENERATIONS=99
export RUN_ERL_LOG_MAXSIZE=2000000
/srv/www/cgi-bin-wf/wf/_build/prod/rel/wf/bin/wf daemon

All this environment optional variables you may find at:
https://www.erlang.org/doc/man/run_erl.html

Finally you must link the
the init.d script to the runlevel subdirectories
/etc/rc3.d

Best with
update-rc.d

Of course you may use system.d, but I don’t understand it.

If you rapplicateion is finally running you may connect to shell of the application, for example
to reload a module
l(module).
etc. with
to_erl /tmp/erl_pipes/wf@x800/erlang.pipe.1

where x800 is the name of your machine.

As said above, that maybe a dirty hack, but for me it works.
Markus

3 Likes

Hi Manfred,

you probably have figured it all out in the meantime…
I just needed command-line arguments myself, so I looked it up.
Maybe it will save some time for someone…

You could use init:get_arguments/0 or init:get_argument/1 for the job.
You pass command lines after <your_release> daemon, and
with get_arguments() you will receive all arguments commandline.
Or with get_argument(arg) you will get only this specific one.

io:format("all flags: ~p~n", [init:get_arguments()]),

$ bin/bumbelbee console -a a1 a2 -b b1 b2 b3 -longer trees grow slow
[..]
Erlang/OTP 25 [erts-13.1.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:30] [jit:ns]

all flags:  [{root,["/home/dieter/plazground/BEAM/erlang/bumbelbee/_build/default/rel/bumbelbee"]},
             {bindir,["/home/dieter/.asdf/installs/erlang/25.1.2/erts-13.1.2/bin"]},
             {progname,["bumbelbee"]},
             {home,["/home/dieter"]},
             {kernel,["shell_history","enabled"]},
             {boot,["/home/dieter/plazground/BEAM/erlang/bumbelbee/_build/default/rel/bumbelbee/releases/0.1.0/start"]},
             {mode,["embedded"]},
             {boot_var,["SYSTEM_LIB_DIR",
                        "/home/dieter/.asdf/installs/erlang/25.1.2/lib"]},
             {config,["/home/dieter/plazground/BEAM/erlang/bumbelbee/_build/default/rel/bumbelbee/releases/0.1.0/sys.config"]},
             {sname,["bumbelbee"]},
             {setcookie,["bumbelbee_cookie"]},
             {a,["a1","a2"]},
             {b,["b1","b2","b3"]},
             {longer,["trees","grow","slow"]}]