bitwalker / distillery

Simplify deployments in Elixir with OTP releases!
MIT License
2.96k stars 397 forks source link

can't loop over require_live_node in command script #650

Closed MagiCrazy closed 5 years ago

MagiCrazy commented 5 years ago

Steps to reproduce

here's the start_app.sh file:

bin/my_app start
...
bin/my_app connect_mnesia

Here's the rel/commands/connect_mnesia.sh file:

#!/bin/sh
set -o posix
set -e
while true; do
        require_live_node
        EXIT_CODE=$?
        if [ $EXIT_CODE -eq 0 ]; then
                break
        fi
done
release_remote_ctl rpc --mfa "Core.ReleaseTasks.connect_mnesia/0"
success

Verbose Logs

$ start_app.sh
▸  Received 'pang' from my_app@172.16.12.34!
▸  Possible reasons for this include:
▸    - The cookie is mismatched between us and the target node
▸    - We cannot establish a remote connection to the node
Node my_app@172.16.12.34 is not running!

Description of issue

We want to launch a command once after the first start of the app. So we don't use boot hooks, just a deploy script that starts our application, then launch a custom command.

As we investigated the issue, we found that the function require_live_node fails using a fail function and that fail function throws an exit 1. We think that require_live_node could throw back a return 1 instead of an exit 1, in order to be more easily manageable in command scripts. Or maybe, we missed something and done it the wrong way, but we can't figure it out!

If our solution is accepted, we could propose a PR 💪

elixir version: 1.7.2 distillery version: 2.0.12

bitwalker commented 5 years ago

You should just use release_ctl ping --name="$NAME" --cookie="$COOKIE", which will return non-zero if the ping fails. require_live_node is designed specifically to require a thing, i.e. fail if the condition is not met. You can take a look at the ping.sh script under priv/libexec/commands for an example.

MagiCrazy commented 5 years ago

OK, so we missed something :) Thanks a lot for your time and your work!