aboutsummaryrefslogtreecommitdiff
path: root/lib/application.ex
blob: e375cf4569eb86f5c35384cf06fd1389c33c6fb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
defmodule Shard.Application do
  @moduledoc """
  Documentation for Shard.
  """

  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    {listen_port, _} = Integer.parse ((System.get_env "PORT") || "4044")

    # Define workers and child supervisors to be supervised
    children = [
      Shard.Identity,
      { DynamicSupervisor, strategy: :one_for_one, name: Shard.DynamicSupervisor },
      
      # Networking
      { SNet.Manager, listen_port },
      { SNet.TCPServer, listen_port },

      # Applications & data store
      Shard.Manager,

      # Web UI
      Plug.Adapters.Cowboy.child_spec(:http, SWeb.HTTPRouter, [], port: listen_port + 1000)
    ]

    # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Shard.Supervisor]
    Supervisor.start_link(children, opts)
  end
end