erlanginets

Erlang: how to embed inets:httpd?


What is the proper way to embed the inets:httpd module inside an existing application?

I would like an example / guidelines to achieving this, please.

Updated: I want to be able to start an inets:httpd service dynamically from within an existing application. I do not want a solution which leverages a boot script as using this method doesn't allow to specify a port dynamically.


Solution

  • The release tools will allow you to put together a complete standalone release including all dependent applications. If that is what you meant by embed then I would start there. It's used for creating erlang applications meant for embededed systems.

    http://www.erlang.org/doc/design_principles/release_structure.html#id2272165 has an overview of this.

    Update After seeing your update. Then all you need to do is:

    inets:start(); inets:start(httpd, ServiceConfig)
    

    somewhere in your application. Keep in mind that when you do this the service will not be handled by inets application takeover and failover but can be soft-code reloaded. You will be responsible for handling this yourself. If you don't mind losing that functionality then this should work just fine.