Search code examples
erlangrebarreltool

How to start a rebar application twice or more with different names?


I have a rebar application called pingpong. After rebar generate I start the packaged application using ./rel/pingpong/bin/pingpong start. The problem is that the erlang VM always has the name -name pingpong@127.0.0.1 but what I want is to start the application once with the name ping@127.0.0.1 and then again with the name pong@127.0.0.1.

I know that the name stays in ./rel/pingpong/releases/VSN/vm.config but I don't want to manually edit the file before starting the application. I want something like pingpong start -name=ping. Is there a way to achieve this?


Solution

  • You can edit the bin/pingpong script to something like thist:

    Instead of

    NAME_ARG=`egrep -e '^-s?name' $RUNNER_ETC_DIR/vm.args`
    

    set:

    NAME_ARG=${NAME_ARG:-`egrep -e '^-s?name' $RUNNER_ETC_DIR/vm.args`}
    

    in this way you will be able to override node name from the command line:

    NAME_ARG="-name myname@localhost" bin/pingpong start
    

    For console/start command:

    Find a line in yout startup script:

    CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH"
    

    Add $NAME_ARG at the end:

     CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH $NAME_ARG"
    

    And don't forget to remove -name NAME from your .args files