Fix ShutdownHandler terminating during normal startup
- Only initiate graceful shutdown for abnormal termination reasons
- Ignore :shutdown, {:shutdown, _}, and :normal termination reasons
- Add logging for SIGTERM handler installation
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
eeeebef34e
commit
60efa7677b
2 changed files with 21 additions and 2 deletions
|
|
@ -69,7 +69,20 @@ defmodule Aprsme.ShutdownHandler do
|
|||
def terminate(reason, state) do
|
||||
Logger.info("ShutdownHandler terminating: #{inspect(reason)}")
|
||||
|
||||
if not state.shutting_down do
|
||||
# Only initiate shutdown for specific reasons, not during normal shutdown
|
||||
should_graceful_shutdown =
|
||||
case reason do
|
||||
# Normal shutdown, don't interfere
|
||||
:shutdown -> false
|
||||
# Normal shutdown with reason
|
||||
{:shutdown, _} -> false
|
||||
# Normal termination
|
||||
:normal -> false
|
||||
# Abnormal termination, do graceful shutdown
|
||||
_ -> true
|
||||
end
|
||||
|
||||
if should_graceful_shutdown and not state.shutting_down do
|
||||
initiate_shutdown(state)
|
||||
# Give some time for the shutdown process
|
||||
Process.sleep(state.drain_timeout)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,13 @@ defmodule Aprsme.SignalHandler do
|
|||
|
||||
def init(_opts) do
|
||||
# Install signal handler for SIGTERM
|
||||
:ok = :os.set_signal(:sigterm, :handle)
|
||||
case :os.set_signal(:sigterm, :handle) do
|
||||
:ok ->
|
||||
Logger.info("SIGTERM signal handler installed")
|
||||
|
||||
error ->
|
||||
Logger.warning("Failed to install SIGTERM handler: #{inspect(error)}")
|
||||
end
|
||||
|
||||
{:ok, %{}}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue