Skip to content

Commit 49dec48

Browse files
author
José Valim
committed
Improve docs for releases
Closes #9187.
1 parent c8c7663 commit 49dec48

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

lib/mix/lib/mix/tasks/release.ex

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,15 @@ defmodule Mix.Tasks.Release do
114114
distribution. For example, if you need to do some prep work before
115115
running the actual system, like migrating your database, `eval` can
116116
be a good fit. Just keep in mind any application you may use during
117-
eval has to be explicitly started.
117+
eval has to be explicitly loaded and/or started.
118+
119+
You can start an application by calling `Application.ensure_all_started/1`.
120+
However, if for some reason you cannot start an application, maybe
121+
cause it will run other services you do not want, you must at least
122+
load the application by calling `Application.load/1`. If you don't
123+
load the application, any attempt at reading its environment or
124+
configuration may fail. Note that if you start an application,
125+
it is automatically loaded before started.
118126
119127
Another way to run commands is with `rpc`, which will connect to the
120128
system currently running and instruct it to execute the given
@@ -133,7 +141,9 @@ defmodule Mix.Tasks.Release do
133141
defmodule MyApp.ReleaseTasks do
134142
def eval_purge_stale_data() do
135143
# Eval commands needs to start the app before
144+
# Or Application.load(:my_app) if you can't start it
136145
Application.ensure_all_started(:my_app)
146+
137147
# Code that purges stale data
138148
...
139149
end
@@ -443,11 +453,25 @@ defmodule Mix.Tasks.Release do
443453
to make sure the Erlang Distribution listens only on a given port
444454
known at runtime, you can set the following:
445455
446-
export ELIXIR_ERL_OPTIONS="-kernel inet_dist_listen_min $BEAM_PORT inet_dist_listen_max $BEAM_PORT"
447-
448-
Or for Windows, in your `env.bat`:
449-
450-
set ELIXIR_ERL_OPTIONS="-kernel inet_dist_listen_min %BEAM_PORT% inet_dist_listen_max %BEAM_PORT%"
456+
case $RELEASE_COMMAND in
457+
start*|daemon*)
458+
ELIXIR_ERL_OPTIONS="-kernel inet_dist_listen_min $BEAM_PORT inet_dist_listen_max $BEAM_PORT"
459+
export ELIXIR_ERL_OPTIONS
460+
;;
461+
*)
462+
;;
463+
esac
464+
465+
Note we only set the port on start/daemon commands. If you also limit
466+
the port on other commands, such as `rpc`, then you will be unable
467+
to establish a remote connection as the port will already be in use
468+
by the node.
469+
470+
On Windows, your `env.bat` would look like this:
471+
472+
IF NOT %RELEASE_COMMAND:start=%==%RELEASE_COMMAND% (
473+
set ELIXIR_ERL_OPTIONS="-kernel inet_dist_listen_min %BEAM_PORT% inet_dist_listen_max %BEAM_PORT%"
474+
)
451475
452476
### Steps
453477

lib/mix/lib/mix/tasks/release.init.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ defmodule Mix.Tasks.Release.Init do
6060
#!/bin/sh
6161
6262
# Sets and enables heart (recommended only in daemon mode)
63-
# if [ "$RELEASE_COMMAND" = "daemon" ] || [ "$RELEASE_COMMAND" = "daemon_iex" ]; then
64-
# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND"
65-
# export HEART_COMMAND
66-
# export ELIXIR_ERL_OPTIONS="-heart"
67-
# fi
63+
# case $RELEASE_COMMAND in
64+
# daemon*)
65+
# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND"
66+
# export HEART_COMMAND
67+
# export ELIXIR_ERL_OPTIONS="-heart"
68+
# ;;
69+
# *)
70+
# ;;
71+
# esac
6872
6973
# Set the release to work across nodes. If using the long name format like
7074
# the one below ([email protected]), you need to also uncomment the

0 commit comments

Comments
 (0)