Firing up an app in a slave node

55 views
Skip to first unread message

pragdave

unread,
Feb 14, 2018, 2:31:44 PM2/14/18
to elixir-lang-core

I’ve trying to create a kind of runner for a set of components, where each component runs on a separate node, and each component is an independent application.

I’ve stolen code from the swarm cluster tests, and I’m successfully creating nodes which seem to contain the Elixir runtime.

As I initialize each node, I make it File.cd into the application’s directory.

However, inside the node, it can’t find the mix.exs file, and so I can’t load the app and its dependencies.

Here we are after doing a user switch into the slave node:

iex(wom...@127.0.0.1)5> ls
.git           .gitignore     README.md      _build         assets         config 
deps           lib            mix.exs        mix.lock       test

iex(wom...@127.0.0.1)6> Mix.Project.get
nil

It feels like I’m making this too difficult: there must be an easier way to kick off applications. If not, any ideas on my directory issue?

Cheers

Dave

Paul Schoenfelder

unread,
Feb 14, 2018, 4:30:19 PM2/14/18
to elixir-l...@googlegroups.com
Have you tried simply running `Application.load(:app)` or `Application.ensure_all_started(:app)`? That should work. If not, it probably means the code path is not configured correctly and you'll need to make sure the code starting the nodes passes in `-pa _build/<env>/lib/*/ebin`. As for why the Mix project isn't loaded, I suspect that has to do with the fact that Mix is being bypassed during startup, and so whatever it does internally isn't happening - that's fine, and expected in this context, but I'm not sure if there is a sane way to initialize Mix post-start. The way releases boot is very similar, and applications are explicitly loaded/started in dependency order after the VM is initialized.

Paul

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/a744b3ae-3189-4f26-8371-c471f0914866%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

José Valim

unread,
Feb 14, 2018, 5:25:36 PM2/14/18
to elixir-l...@googlegroups.com

pragdave

unread,
Feb 15, 2018, 4:40:47 PM2/15/18
to elixir-lang-core


On Wednesday, February 14, 2018 at 4:25:36 PM UTC-6, José Valim wrote:
We also do a similar setup in firenest test suite: https://github.com/phoenixframework/firenest/blob/master/test/shared/test.ex


I'm trying not to use a boot loader: the assumption is that the code for the spawned node is not available within the spawning node.

That's why I was trying to get to mix: when I try to do an `ensure_all_started` on the spawned app, I get `Dictionary.app` not found, so I was assuming mix does something groovy to set up paths.

I theory I've cloned the code path from the main app, but replaced its bin and ebin with the spawned apps versions.

I'll carry on digging. 

Thanks

Dave

pragdave

unread,
Feb 15, 2018, 4:54:50 PM2/15/18
to elixir-lang-core

Oh, and just to clarify: I'm trying to do this in dev mode, so I want to run the application from its project directory.

I may have to bit the bullet and just spawn a shell and run mix in it... :(

Paul Schoenfelder

unread,
Feb 15, 2018, 5:29:48 PM2/15/18
to elixir-l...@googlegroups.com
I would second the boot loader approach when viable, but since it's not in your case, then there is nothing particularly special about how the paths are set up, you just need to add the lib directory from your Elixir install (e.g. `-pa <path to elixir/lib/*/ebin`) and the build directory where the project code is (e.g. `-pa _build/<env>/lib/*/ebin`). If you need to compile the project as part of this process, then indeed you might have better luck just running Mix via `System.cmd` - there isn't necessarily anything wrong with that approach, but then it's entirely up to you to ensure that the spawned nodes are cleaned up before shutting down the spawning node.

On Thu, Feb 15, 2018 at 4:54 PM, pragdave <prag...@gmail.com> wrote:

Oh, and just to clarify: I'm trying to do this in dev mode, so I want to run the application from its project directory.

I may have to bit the bullet and just spawn a shell and run mix in it... :(

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

pragdave

unread,
Feb 15, 2018, 10:06:12 PM2/15/18
to elixir-lang-core
The problem is that I also have to load the dependencies (at least I think I do), which is why I was trying to get to Mix programmatically.



On Thursday, February 15, 2018 at 4:29:48 PM UTC-6, Paul Schoenfelder wrote:
I would second the boot loader approach when viable, but since it's not in your case, then there is nothing particularly special about how the paths are set up, you just need to add the lib directory from your Elixir install (e.g. `-pa <path to elixir/lib/*/ebin`) and the build directory where the project code is (e.g. `-pa _build/<env>/lib/*/ebin`). If you need to compile the project as part of this process, then indeed you might have better luck just running Mix via `System.cmd` - there isn't necessarily anything wrong with that approach, but then it's entirely up to you to ensure that the spawned nodes are cleaned up before shutting down the spawning node.
On Thu, Feb 15, 2018 at 4:54 PM, pragdave <prag...@gmail.com> wrote:

Oh, and just to clarify: I'm trying to do this in dev mode, so I want to run the application from its project directory.

I may have to bit the bullet and just spawn a shell and run mix in it... :(

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages