|
1 |
| -# nopmd (No Port Mapper Daemon) |
| 1 | +# nopmd (no-port-mapper-daemon) |
2 | 2 |
|
3 |
| -If you run distributed services such like pubsubs or message brokers between regions with EPMD, all your nodenames and ports are exposed over the internet, and you've probably got more ports open in your firewalls than actual services running behind them. Yuck. |
| 3 | +**NOTE:** Tested only on OTP 23+ |
| 4 | + |
| 5 | +If you run distributed services such like pubsubs or message brokers between regions with EPMD, all your nodenames and ports are either exposed over the internet or you've written scripts to forward ports via ssh, and you've probably got more ports open in your firewalls than actual services running behind them. Yuck. |
4 | 6 |
|
5 | 7 | Don't you wish you could just decide on a port, append it to the nodename and call it a day?
|
6 | 8 |
|
7 | 9 | ## Elixir
|
8 | 10 |
|
9 |
| - # mix.exs |
10 |
| - {:nopmd, "> 0.0.0"} |
| 11 | +```shell |
| 12 | +# mix.exs |
| 13 | +{:nopmd, "> 0.0.0"} |
| 14 | + |
| 15 | +# nodename example (--sname not supported, obviously) |
| 16 | + |
| 17 | + |
| 18 | +# ipv6 nodename example |
| 19 | +--name mynode@::1:8080 |
| 20 | + |
| 21 | +# erl flags (go in --erl "...") |
| 22 | +-pa _build/(dev|prod)/lib/nopmd/ebin \ |
| 23 | +-proto_dist nopmd_(inet|inet6)_(tcp|tls)_dist \ |
| 24 | +-start_epmd false |
| 25 | +``` |
| 26 | + |
| 27 | +### Elixir Releases |
| 28 | + |
| 29 | +Uncomment `RELEASE_DISTRIBUTION` and `RELEASE_NODE` in `env.sh.eex`, then add the following and modify as needed: |
| 30 | + |
| 31 | +```shell |
| 32 | +export RELEASE_PORT=${RELEASE_PORT:-"8080"} |
| 33 | +export RELEASE_AUX_PORT=${RELEASE_AUX_PORT:-"8000"} |
| 34 | +export RELEASE_PROTO_DIST=nopmd_inet_tcp |
| 35 | +export ELIXIR_ERL_OPTIONS="-pa lib/nopmd-0.1.0/ebin -proto_dist $RELEASE_PROTO_DIST -start_epmd false" |
11 | 36 |
|
12 |
| - # nodename example (--sname not supported, obviously) |
13 |
| - |
| 37 | +case $RELEASE_COMMAND in |
| 38 | + start*|daemon*) |
| 39 | + export RELEASE_NODE=$RELEASE_NODE:$RELEASE_PORT |
| 40 | + ;; |
| 41 | + *) |
| 42 | + export ELIXIR_ERL_OPTIONS="$ELIXIR_ERL_OPTIONS -name $RELEASE_NODE:$RELEASE_AUX_PORT -kernel logger_level error" |
| 43 | + export RELEASE_NODE=$RELEASE_NODE:$RELEASE_PORT |
| 44 | + ;; |
| 45 | +esac |
| 46 | +``` |
14 | 47 |
|
15 |
| - # ipv6 nodename example |
16 |
| - --name mynode@::1:8080 |
| 48 | +**NOTE:** When using ssl/tls, you must add all your ssl dist opts to the `ELIXIR_ERL_OPTIONS` line in this example. |
17 | 49 |
|
18 |
| - # erl flags (put in --erl "..." when running with iex) |
19 |
| - -pa _build/(dev|prod)/lib/nopmd/ebin \ |
20 |
| - -proto_dist nopmd_(inet|inet6)_(tcp|tls)_dist \ |
21 |
| - -no_epmd |
| 50 | +### Distillery Releases |
| 51 | + |
| 52 | +Make all the necessary modifications to `vm.args`. Since Distillery doesn't provide any way to add flags when instantiating commands, the only command that will work is `start`, if you want to stop, rpc remsh, etc, you will have to write scripts for them manually and use overlays to overwrite the existing scripts for those commands in `libexec/commands/` (or just use elixir releases). |
| 53 | + |
| 54 | +**NOTE:** Distillery doesn't seem to care about distribution encryption 😕, if you're using encryption, you must add `:ssl` to `extra_applications` in `mix.exs` and include all relevent ssl opts in your overlays. |
22 | 55 |
|
23 | 56 | ## Erlang (Hex)
|
24 | 57 |
|
25 |
| - # rebar.config |
26 |
| - {deps, [nopmd]}. |
27 |
| - {plugins, [rebar3_hex]}. |
| 58 | +```shell |
| 59 | +# rebar.config |
| 60 | +{deps, [nopmd]}. |
| 61 | +{plugins, [rebar3_hex]}. |
| 62 | + |
| 63 | +# nodename example (-sname not supported, obviously) |
| 64 | + |
| 65 | + |
| 66 | +# ipv6 nodename example |
| 67 | +-name mynode@::1:8080 |
| 68 | + |
| 69 | +# flags |
| 70 | +-pa _build/default/lib/nopmd/ebin |
| 71 | +-proto_dist nopmd_(inet|inet6)_(tcp|tls)_dist |
| 72 | +-start_epmd false |
| 73 | +``` |
| 74 | + |
| 75 | +### Relx Releases |
28 | 76 |
|
29 |
| - # nodename example (-sname not supported, obviously) |
30 |
| - |
| 77 | +Add `-name ${NODE_NAME}` to `vm.args.src`. The following commands will have to be used as such: |
31 | 78 |
|
32 |
| - # ipv6 nodename example |
33 |
| - -name mynode@::1:8080 |
| 79 | +```shell |
| 80 | +[email protected]:8080 \_build/default/rel/myapp/bin/myapp daemon |
| 81 | +[email protected] ERL_DIST_PORT=8080 \_build/default/rel/myapp/bin/myapp pid |
| 82 | +[email protected] ERL_DIST_PORT=8080 \_build/default/rel/myapp/bin/myapp stop |
| 83 | +``` |
34 | 84 |
|
35 |
| - # flags |
36 |
| - -pa _build/default/lib/nopmd/ebin |
37 |
| - -proto_dist nopmd_(inet|inet6)_(tcp|tls)_dist |
38 |
| - -no_epmd |
| 85 | +Remsh will have to be done manually or the generated `mynode` script modified. |
39 | 86 |
|
40 | 87 | ## Build & Test Locally
|
41 | 88 |
|
42 |
| - $ rebar3 compile |
43 |
| - $ epmd -kill |
44 |
| - |
45 |
| - $ erl -name [email protected]:8080 \ |
46 |
| - -pa _build/default/lib/nopmd/ebin \ |
47 |
| - -proto_dist nopmd_inet_tcp \ |
48 |
| - -no_epmd |
49 |
| - |
50 |
| - $ erl -name mynode@::1:8080 \ |
51 |
| - -pa _build/default/lib/nopmd/ebin \ |
52 |
| - -proto_dist nopmd_inet6_tcp \ |
53 |
| - -no_epmd |
54 |
| - |
55 |
| - $ erl -name [email protected]:8080 \ |
56 |
| - -pa _build/default/lib/nopmd/ebin \ |
57 |
| - -proto_dist nopmd_inet_tls \ |
58 |
| - -ssl_dist_opt server_certfile cert.pem \ |
59 |
| - -ssl_dist_opt server_secure_renegotiate true client_secure_renegotiate true \ |
60 |
| - -no_epmd |
61 |
| - |
62 |
| - $ erl -name mynode@::1:8080 \ |
63 |
| - -pa _build/default/lib/nopmd/ebin \ |
64 |
| - -proto_dist nopmd_inet6_tls \ |
65 |
| - -ssl_dist_opt server_certfile cert.pem \ |
66 |
| - -ssl_dist_opt server_secure_renegotiate true client_secure_renegotiate true \ |
67 |
| - -no_epmd |
| 89 | +```shell |
| 90 | +$ rebar3 compile |
| 91 | +$ epmd -kill |
| 92 | + |
| 93 | +$ erl -name [email protected]:8080 \ |
| 94 | +-pa _build/default/lib/nopmd/ebin \ |
| 95 | +-proto_dist nopmd_inet_tcp \ |
| 96 | +-start_epmd false |
| 97 | + |
| 98 | +$ erl -name mynode@::1:8080 \ |
| 99 | +-pa _build/default/lib/nopmd/ebin \ |
| 100 | +-proto_dist nopmd_inet6_tcp \ |
| 101 | +-start_epmd false |
| 102 | + |
| 103 | +$ erl -name [email protected]:8080 \ |
| 104 | +-pa _build/default/lib/nopmd/ebin \ |
| 105 | +-proto_dist nopmd_inet_tls \ |
| 106 | +-ssl_dist_opt server_certfile cert.pem \ |
| 107 | +-start_epmd false |
| 108 | + |
| 109 | +$ erl -name mynode@::1:8080 \ |
| 110 | +-pa _build/default/lib/nopmd/ebin \ |
| 111 | +-proto_dist nopmd_inet6_tls \ |
| 112 | +-ssl_dist_opt server_certfile cert.pem \ |
| 113 | +-start_epmd false |
| 114 | +``` |
0 commit comments