I'm trying to get my head around supervisors in OTP and such in erlang (although I am using elixir) and I can't seem to figure out why the main supervisor tree won't start.
I am making a http server with one listener worker, and a supervisor has handlers (dynamically started). I can start each of these on their own, and I can start the tree if the listener is the only thing in the tree.
Here's the supervisor definitions in elixir
defmodule HTTPServer.Supervisor do
use Supervisor.Behaviour
def start_link(port) do
:supervisor.start_link({ :local, :sup }, __MODULE__, [port])
end
def init(port) do
tree = [
worker(HTTPServer.Listener, [port], id: :listener_sup),
supervisor(HTTPServer.HandlerSupervisor, [], shutdown: :infinity,
modules: [])
]
supervise(tree, strategy: :one_for_one)
end
end
defmodule HTTPServer.HandlerSupervisor do
use Supervisor.Behaviour
def start_link(_) do
IO.puts "starting handler supervisor"
:supervisor.start_link({ :local, :handler_sup }, __MODULE__, [])
end
def init(_) do
tree = [ worker(HTTPServer.Handler, [], restart: :temporary,
id: nil) ]
supervise(tree, strategy: :simple_one_for_one)
end
def start_child([socket]) do
IO.puts "starting handler child"
:supervisor.start_child(:handler_sup, [socket])
end
end
Something about the supervisor definition in the tree is wrong and I can't figure out what, and it seems to be basically the only thing holding my project back.
Thanks for any assistance!