- Fix leader election guard test for :undefined pid - Fix cpu_sup.util() pattern matching to handle numeric return - Fix encoding_utils to always return explicit nil when needed - Remove unused finite_float? function - Fix signal handler to match :ok return from :os.set_signal/2 - Remove redundant catch-all pattern in database metrics - Fix Gridsquare pattern matching in info_live template - Remove unnecessary nil check for calculate_course result - Fix get_packet_received_at to not check for nil (always returns DateTime) - Remove redundant catch-all pattern in weather format_weather_value - Fix query builder to use from(p in Packet) instead of bare Packet atom Reduced dialyzer errors from 49 to 6. Remaining warnings are mostly false positives from template compilation and overloaded function specs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
890 B
Elixir
39 lines
890 B
Elixir
defmodule Aprsme.SignalHandler do
|
|
@moduledoc """
|
|
Handles OS signals like SIGTERM for graceful shutdown.
|
|
"""
|
|
|
|
use GenServer
|
|
|
|
require Logger
|
|
|
|
def start_link(opts) do
|
|
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
|
|
end
|
|
|
|
def init(_opts) do
|
|
# Install signal handler for SIGTERM
|
|
# :os.set_signal/2 always returns :ok
|
|
:ok = :os.set_signal(:sigterm, :handle)
|
|
Logger.info("SIGTERM signal handler installed")
|
|
|
|
{:ok, %{}}
|
|
end
|
|
|
|
# Handle SIGTERM signal
|
|
def handle_info({:signal, :sigterm}, state) do
|
|
Logger.info("Received SIGTERM signal, initiating graceful shutdown...")
|
|
|
|
# Trigger graceful shutdown
|
|
spawn(fn ->
|
|
Aprsme.ShutdownHandler.shutdown()
|
|
end)
|
|
|
|
{:noreply, state}
|
|
end
|
|
|
|
def handle_info(msg, state) do
|
|
Logger.debug("SignalHandler received unexpected message: #{inspect(msg)}")
|
|
{:noreply, state}
|
|
end
|
|
end
|