Skip to content

Instantly share code, notes, and snippets.

@rlb3
Created May 4, 2022 03:23
Show Gist options
  • Save rlb3/d96caccc2d9abb29b9cfc1872fec4159 to your computer and use it in GitHub Desktop.
Save rlb3/d96caccc2d9abb29b9cfc1872fec4159 to your computer and use it in GitHub Desktop.

Erlang ships with two amazing command line utilities which you can use to run any application and connect to it any time you want. They are called run_erl and to_erl:

run_erl ./my_app /dir/for/logging iex -S mix The command above will execute iex -S mix and give it a name of my_app and will log any entries to “/dir/for/logging”. Make sure the logging directory exists otherwise run_erl may fail silently.

Now you can connect to the iex terminal of that node at any time by doing this:

to_erl ./my_app This means that, if you use run_erl to start Elixir with IEx inside Docker, you can connect to IEx and issue :init.stop/0 for proper node shutdown. :init.stop/0 will go application by application and shutdown their supervision tree respecting the configured timeouts. You can automate it by running:

echo ":init.stop" > to_erl ./my_app And that’s it! If you are using releases, for example via Distillery, they handle this stuff automatically for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment