Disable signal trap for usage kemal with outher tools

This commit is contained in:
Alexey Vasiliev 2022-07-13 16:52:26 +03:00
parent 05d55540b9
commit 88807b90c6
No known key found for this signature in database
GPG key ID: 73BC1D843B7DCE42
3 changed files with 13 additions and 1 deletions

View file

@ -40,6 +40,14 @@ describe "Config" do
config.shutdown_message.should eq true config.shutdown_message.should eq true
end end
it "toggles the disable trap signal" do
config = Kemal.config
config.disable_trap_signal = false
config.disable_trap_signal.should eq false
config.disable_trap_signal = true
config.disable_trap_signal.should eq true
end
it "adds custom options" do it "adds custom options" do
config = Kemal.config config = Kemal.config
ARGV.push("--test") ARGV.push("--test")

View file

@ -89,6 +89,8 @@ module Kemal
end end
private def self.setup_trap_signal private def self.setup_trap_signal
return if Kemal.config.disable_trap_signal
Signal::INT.trap do Signal::INT.trap do
log "#{Kemal.config.app_name} is going to take a rest!" if Kemal.config.shutdown_message log "#{Kemal.config.app_name} is going to take a rest!" if Kemal.config.shutdown_message
Kemal.stop Kemal.stop

View file

@ -21,7 +21,7 @@ module Kemal
{% end %} {% end %}
property host_binding, ssl, port, env, public_folder, logging, running property host_binding, ssl, port, env, public_folder, logging, running
property always_rescue, server : HTTP::Server?, extra_options, shutdown_message property always_rescue, server : HTTP::Server?, extra_options, shutdown_message, disable_trap_signal
property serve_static : (Bool | Hash(String, Bool)) property serve_static : (Bool | Hash(String, Bool))
property static_headers : (HTTP::Server::Response, String, File::Info -> Void)? property static_headers : (HTTP::Server::Response, String, File::Info -> Void)?
property powered_by_header : Bool = true, app_name property powered_by_header : Bool = true, app_name
@ -41,6 +41,7 @@ module Kemal
@default_handlers_setup = false @default_handlers_setup = false
@running = false @running = false
@shutdown_message = true @shutdown_message = true
@disable_trap_signal = false
@handler_position = 0 @handler_position = 0
end end
@ -61,6 +62,7 @@ module Kemal
@router_included = false @router_included = false
@handler_position = 0 @handler_position = 0
@default_handlers_setup = false @default_handlers_setup = false
@disable_trap_signal = false
HANDLERS.clear HANDLERS.clear
CUSTOM_HANDLERS.clear CUSTOM_HANDLERS.clear
FILTER_HANDLERS.clear FILTER_HANDLERS.clear