Compare commits

..

No commits in common. "f21b48eadff2d847072fd5aef7d24cc0befb6469" and "83c7c11b97c71d5d8bf6bbb7ccc5789c63a40184" have entirely different histories.

9 changed files with 8 additions and 95 deletions

View file

@ -2,6 +2,5 @@ import Config
config :ha_handler,
http_port: 4000,
acme_challenge_path: "acme-challenge",
haproxy_socket: System.get_env("HAPROXY_SOCKET") || "/var/run/haproxy.sock"

View file

@ -3,5 +3,4 @@ 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

View file

@ -10,7 +10,7 @@ defmodule HAHandler.Application do
@impl true
def start(_type, _args) do
children = [
{Plug.Cowboy, scheme: :http, plug: HAHandler.Web.Router, options: [port: http_port()]}
{Plug.Cowboy, scheme: :http, plug: HAHandler.Web, options: [port: http_port()]}
]
# See https://hexdocs.pm/elixir/Supervisor.html

View file

@ -1,9 +1,13 @@
defmodule HAHandler.Web.Controller do
defmodule HAHandler.Web do
import Plug.Conn
alias HAHandler.HAProxy
def index(conn) do
def init(opts) do
opts
end
def call(conn, _opts) do
{:ok, hostname} = :inet.gethostname()
stats = HAProxy.get_stats()

View file

@ -1,35 +0,0 @@
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
View file

@ -7,8 +7,7 @@ defmodule HAHandler.MixProject do
version: "0.1.0",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
releases: releases()
deps: deps()
]
end
@ -29,18 +28,4 @@ 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

View file

@ -1,17 +0,0 @@
#!/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 %>

View file

@ -1,11 +0,0 @@
## 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

View file

@ -1,11 +0,0 @@
## 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