mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
use trap_signal in run
This commit is contained in:
parent
88807b90c6
commit
db87d82709
3 changed files with 8 additions and 20 deletions
|
@ -40,14 +40,6 @@ 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")
|
||||||
|
|
16
src/kemal.cr
16
src/kemal.cr
|
@ -7,18 +7,18 @@ require "./kemal/helpers/*"
|
||||||
|
|
||||||
module Kemal
|
module Kemal
|
||||||
# Overload of `self.run` with the default startup logging.
|
# Overload of `self.run` with the default startup logging.
|
||||||
def self.run(port : Int32?, args = ARGV)
|
def self.run(port : Int32?, args = ARGV, trap_signal : Bool = true)
|
||||||
self.run(port, args) { }
|
self.run(port, args, trap_signal) { }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overload of `self.run` without port.
|
# Overload of `self.run` without port.
|
||||||
def self.run(args = ARGV)
|
def self.run(args = ARGV, trap_signal : Bool = true)
|
||||||
self.run(nil, args: args)
|
self.run(nil, args: args, trap_signal: trap_signal)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overload of `self.run` to allow just a block.
|
# Overload of `self.run` to allow just a block.
|
||||||
def self.run(args = ARGV, &block)
|
def self.run(args = ARGV, &block)
|
||||||
self.run(nil, args: args, &block)
|
self.run(nil, args: args, trap_signal: true, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The command to run a `Kemal` application.
|
# The command to run a `Kemal` application.
|
||||||
|
@ -27,7 +27,7 @@ module Kemal
|
||||||
#
|
#
|
||||||
# To use custom command line arguments, set args to nil
|
# To use custom command line arguments, set args to nil
|
||||||
#
|
#
|
||||||
def self.run(port : Int32? = nil, args = ARGV, &block)
|
def self.run(port : Int32? = nil, args = ARGV, trap_signal : Bool = true, &block)
|
||||||
Kemal::CLI.new args
|
Kemal::CLI.new args
|
||||||
config = Kemal.config
|
config = Kemal.config
|
||||||
config.setup
|
config.setup
|
||||||
|
@ -36,7 +36,7 @@ module Kemal
|
||||||
# Test environment doesn't need to have signal trap and logging.
|
# Test environment doesn't need to have signal trap and logging.
|
||||||
if config.env != "test"
|
if config.env != "test"
|
||||||
setup_404
|
setup_404
|
||||||
setup_trap_signal
|
setup_trap_signal if trap_signal
|
||||||
end
|
end
|
||||||
|
|
||||||
server = config.server ||= HTTP::Server.new(config.handlers)
|
server = config.server ||= HTTP::Server.new(config.handlers)
|
||||||
|
@ -89,8 +89,6 @@ 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
|
||||||
|
|
|
@ -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, disable_trap_signal
|
property always_rescue, server : HTTP::Server?, extra_options, shutdown_message
|
||||||
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,7 +41,6 @@ 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
|
||||||
|
|
||||||
|
@ -62,7 +61,6 @@ 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue