@@ -114,7 +114,15 @@ defmodule Mix.Tasks.Release do
114
114
distribution. For example, if you need to do some prep work before
115
115
running the actual system, like migrating your database, `eval` can
116
116
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.
118
126
119
127
Another way to run commands is with `rpc`, which will connect to the
120
128
system currently running and instruct it to execute the given
@@ -133,7 +141,9 @@ defmodule Mix.Tasks.Release do
133
141
defmodule MyApp.ReleaseTasks do
134
142
def eval_purge_stale_data() do
135
143
# Eval commands needs to start the app before
144
+ # Or Application.load(:my_app) if you can't start it
136
145
Application.ensure_all_started(:my_app)
146
+
137
147
# Code that purges stale data
138
148
...
139
149
end
@@ -443,11 +453,25 @@ defmodule Mix.Tasks.Release do
443
453
to make sure the Erlang Distribution listens only on a given port
444
454
known at runtime, you can set the following:
445
455
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
+ )
451
475
452
476
### Steps
453
477
0 commit comments