Skip to content

Load a single beam file, apps (a set of beams), or an erlang release (a set of apps) to a node.

License

Notifications You must be signed in to change notification settings

Tubitv/ex_loader

Repository files navigation

ExLoader

Load a single beam file, an app (a set of beams), or an erlang release (a set of apps) to a remote node. It is useful for distribute the binary to dynamically created remote node.

Things to do:

  • load sys.config to remote node
  • better error logging if remote node failed to load modules or apps
  • support upgrade release

Installation

ex_loader is available in hex, it can be installed by adding ex_loader to your list of dependencies in mix.exs:

def deps do
  [{:ex_loader, "~> 0.3.0"}]
end

Usage

After adding ex_loader as a dependency, you can easily call the following API:

# load a single module to a remote node, say "hello.beam" provide a func called ``say(msg)``
{:ok, module} = ExLoader.load_module("hello.beam", :"test-node@hostname")

# then the module is available. You can access it in remote node, or call it with RPC.
"hello world" = :rpc.call(:"test-node@hostname", module, :say, ["hello world"])

# load a list of apps from a release (generated by distillery). Say example_app.tar.gz contains an app called :example_app.
:ok = ExLoader.load_apps("example_app.tar.gz", [:example_app], :"test-node@hostname")

# now :example_app is started in :"test-node@hostname" (dependencies are resolved automatically). Let's assume this app will automatically start a GenServer called ExampleApp.Server, and it has a function ``hello(msg)``.
"hello world" = :rpc.call(:"test-node@hostname", ExampleApp.Server, :hello, ["world"])

# load a release. Say example_complex_app.tar.gz.
:ok = ExLoader.load_release("example_complex_app.tar.gz", :"test-node@hostname")

# all applications in this release are started in node :"test-node@hostname". The configuration ``sys.config`` in the release will be honored and loaded with ``Application.put_env`` so that you don't need to worry about configuration. If the release depends on environment variable, please set them before loading the release.
# you can interact with the functionality provided by the release now. Let's assume it contains an API server which handles the request to http://hostname:8888/hello/?msg=xxx.
{:ok, %HTTPoison.Response{body: "hello world"}} = HttpPoison.get("http://hostname:8888/hello/?msg=world")

Full documentation can be found at https://hexdocs.pm/ex_loader.

About

Load a single beam file, apps (a set of beams), or an erlang release (a set of apps) to a node.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published