views:

141

answers:

3

I have several nodes running in an erlang cluster, each using the same magic cookie and trusted by each other. I want to have one master node send code and modules to the other nodes. How can I do this?

+2  A: 

use nl(module_name). to load code on all the nodes.

Abhijith
Wow, I passed this over earlier, thought it was part of something much more complex, so I ignored it!!! I cannot believe it is so easy in Erlang. I'm testing on three nodes on a single linux laptop though. Does it work over the network?
Zubair
yes it does work over the network.
Abhijith
ok, thanks. And what an amazing feature too :)
Zubair
I'm not sure this is what you want: nl loads a module on all nodes, but the beam code must be already present on the remote node.
filippo
No. Its not required to have the code on the remote node. Thats the whole point of nl.
Abhijith
I just tested this on a set of local nodes where erl is started in different directories and it works fine so I'm guessing that the beam files are sent over to the remote nodes. Yes, in fact try using nl without compiling a module and it wont work.
Zubair
Yes, you _need_ to compile it. I should have been explicit about that. If you want to send code/string over the network and load it, then I think the following link might help. http://www.trapexit.org/String_Eval. But you will have to write some code to enable your program to do it.
Abhijith
+1  A: 

Check out my etest project for an example of programmatically injecting a set of modules on all nodes and then starting it.

The core of this is pretty much the following code:

{Mod, Bin, File} = code:get_object_code(Mod),
{_Replies, _} = rpc:multicall(Nodes, code, load_binary,
                              [Mod, File, Bin]),
Dustin
Do you use "nl" to send the code to the remote nodes?
Zubair
No. That would be terribly inconvenient. The code I posted here *IS* how I send the code to the remote nodes. That whole test framework I pointed you to includes distributing and launching remote code with examples and documentation. Look through it. Understand it. :)
Dustin
Ok, I will do. Thanks
Zubair
+1  A: 

You could check this post for a more detailed example

Alin
I checked the post. I have a further question. Why does it use :rpc:call('[email protected]',erlang,load_module, [Mod, Bin]).: instead of the "nl" command?
Zubair
nl only works in the shell, unless you call c:nl/1. Check out its code in c.erl, it's not much more than the rpc example.
rvirding
Ah, yes, now I remember the differences between shell and Erlang modules. I'll look into this, thanks
Zubair