Compare commits
3 commits
83c7c11b97
...
f21b48eadf
Author | SHA1 | Date | |
---|---|---|---|
|
f21b48eadf | ||
|
50326536b1 | ||
|
ce26909daa |
9 changed files with 95 additions and 8 deletions
|
@ -2,5 +2,6 @@ import Config
|
|||
|
||||
config :ha_handler,
|
||||
http_port: 4000,
|
||||
acme_challenge_path: "acme-challenge",
|
||||
haproxy_socket: System.get_env("HAPROXY_SOCKET") || "/var/run/haproxy.sock"
|
||||
|
||||
|
|
|
@ -3,4 +3,5 @@ defmodule HAHandler do
|
|||
|
||||
def http_port, do: Application.get_env(:ha_handler, :http_port)
|
||||
def haproxy_socket, do: Application.get_env(:ha_handler, :haproxy_socket)
|
||||
def acme_challenge_path, do: Application.get_env(:ha_handler, :acme_challenge_path)
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ defmodule HAHandler.Application do
|
|||
@impl true
|
||||
def start(_type, _args) do
|
||||
children = [
|
||||
{Plug.Cowboy, scheme: :http, plug: HAHandler.Web, options: [port: http_port()]}
|
||||
{Plug.Cowboy, scheme: :http, plug: HAHandler.Web.Router, options: [port: http_port()]}
|
||||
]
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
defmodule HAHandler.Web do
|
||||
defmodule HAHandler.Web.Controller do
|
||||
import Plug.Conn
|
||||
|
||||
alias HAHandler.HAProxy
|
||||
|
||||
def init(opts) do
|
||||
opts
|
||||
end
|
||||
|
||||
def call(conn, _opts) do
|
||||
def index(conn) do
|
||||
{:ok, hostname} = :inet.gethostname()
|
||||
|
||||
stats = HAProxy.get_stats()
|
35
lib/ha_handler/web/router.ex
Normal file
35
lib/ha_handler/web/router.ex
Normal file
|
@ -0,0 +1,35 @@
|
|||
defmodule HAHandler.Web.Router do
|
||||
@moduledoc """
|
||||
This module dispatch incoming HTTP requests to their
|
||||
related logic. Please refer to [1] for details.
|
||||
|
||||
[1] https://hexdocs.pm/plug/Plug.Router.html#content
|
||||
"""
|
||||
|
||||
use Plug.Router
|
||||
|
||||
import HAHandler, only: [acme_challenge_path: 0]
|
||||
|
||||
alias HAHandler.Web.Controller
|
||||
|
||||
# Note for plugs: oder is important, as a plug may stop
|
||||
# want to stop the pipeline!
|
||||
|
||||
plug Plug.Logger, log: :debug
|
||||
# Note: `plug` is a macro, hence evaluated at
|
||||
# compile-time. The configuration (which path to
|
||||
# serve) cannot be modified at runtime with this
|
||||
# system.
|
||||
plug Plug.Static,
|
||||
at: "/.well-known/acme-challenge/",
|
||||
from: acme_challenge_path()
|
||||
|
||||
plug :match
|
||||
plug :dispatch
|
||||
|
||||
get "/", do: Controller.index(conn)
|
||||
|
||||
match _ do
|
||||
send_resp(conn, 404, "Not found")
|
||||
end
|
||||
end
|
17
mix.exs
17
mix.exs
|
@ -7,7 +7,8 @@ defmodule HAHandler.MixProject do
|
|||
version: "0.1.0",
|
||||
elixir: "~> 1.12",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps()
|
||||
deps: deps(),
|
||||
releases: releases()
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -28,4 +29,18 @@ defmodule HAHandler.MixProject do
|
|||
{:poison, "~> 5.0"}
|
||||
]
|
||||
end
|
||||
|
||||
# See https://hexdocs.pm/mix/Mix.Tasks.Release.html for details.
|
||||
defp releases do
|
||||
[
|
||||
ha_handler: [
|
||||
include_executables_for: [:unix],
|
||||
applications: [runtime_tools: :permanent],
|
||||
include_erts: true,
|
||||
config_providers: [
|
||||
{Config.Reader, {:system, "HA_HANDLER_CONFIG_DIR", "config.exs"}}
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
17
rel/env.sh.eex
Normal file
17
rel/env.sh.eex
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Sets and enables heart (recommended only in daemon mode)
|
||||
# case $RELEASE_COMMAND in
|
||||
# daemon*)
|
||||
# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND"
|
||||
# export HEART_COMMAND
|
||||
# export ELIXIR_ERL_OPTIONS="-heart"
|
||||
# ;;
|
||||
# *)
|
||||
# ;;
|
||||
# esac
|
||||
|
||||
# Set the release to work across nodes.
|
||||
# RELEASE_DISTRIBUTION must be "sname" (local), "name" (distributed) or "none".
|
||||
# export RELEASE_DISTRIBUTION=name
|
||||
# export RELEASE_NODE=<%= @release.name %>
|
11
rel/remote.vm.args.eex
Normal file
11
rel/remote.vm.args.eex
Normal file
|
@ -0,0 +1,11 @@
|
|||
## Customize flags given to the VM: https://erlang.org/doc/man/erl.html
|
||||
## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here
|
||||
|
||||
## Number of dirty schedulers doing IO work (file, sockets, and others)
|
||||
##+SDio 5
|
||||
|
||||
## Increase number of concurrent ports/sockets
|
||||
##+Q 65536
|
||||
|
||||
## Tweak GC to run more often
|
||||
##-env ERL_FULLSWEEP_AFTER 10
|
11
rel/vm.args.eex
Normal file
11
rel/vm.args.eex
Normal file
|
@ -0,0 +1,11 @@
|
|||
## Customize flags given to the VM: https://erlang.org/doc/man/erl.html
|
||||
## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here
|
||||
|
||||
## Number of dirty schedulers doing IO work (file, sockets, and others)
|
||||
##+SDio 5
|
||||
|
||||
## Increase number of concurrent ports/sockets
|
||||
##+Q 65536
|
||||
|
||||
## Tweak GC to run more often
|
||||
##-env ERL_FULLSWEEP_AFTER 10
|
Loading…
Reference in a new issue