aprs.me/lib/aprsme/signal_handler.ex
Graham McIntire eeeebef34e
Fix PgBouncer database connection and graceful shutdown
- Add SKIP_DB_CREATE env var to skip database creation when using PgBouncer
- Fix redis_children() to return proper child specs
- Implement zero-downtime graceful shutdown without user notifications
- Add health check plug for Kubernetes probes
- Remove user-facing shutdown notifications for seamless deployments

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-26 15:51:06 -05:00

37 lines
796 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
:ok = :os.set_signal(:sigterm, :handle)
{: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