feat(agent): supervisor boots reporter when config is present

This commit is contained in:
Carsten 2026-04-21 22:09:29 +02:00
parent 3ae38f95a9
commit bfe39e71e1
3 changed files with 35 additions and 11 deletions

View file

@ -1,20 +1,32 @@
defmodule ProxmoxAgent.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
require Logger
@impl true
def start(_type, _args) do
children = [
# Starts a worker by calling: ProxmoxAgent.Worker.start_link(arg)
# {ProxmoxAgent.Worker, arg}
]
children =
case load_config() do
{:ok, cfg} ->
Logger.info("agent: starting with host_id=#{cfg.host_id}")
[{ProxmoxAgent.Reporter, cfg}]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: ProxmoxAgent.Supervisor]
Supervisor.start_link(children, opts)
{:error, reason} ->
Logger.error("agent: no config loaded (#{inspect(reason)}); running in idle mode")
[]
end
Supervisor.start_link(children, strategy: :one_for_one, name: ProxmoxAgent.Supervisor)
end
defp load_config do
path =
System.get_env("AGENT_CONFIG") ||
Application.get_env(:agent, :config_path, "/etc/proxmox-monitor/agent.toml")
case File.exists?(path) do
true -> ProxmoxAgent.Config.load(path)
false -> {:error, {:file_missing, path}}
end
end
end