ruby - Sinatra Restarting Webrick Server after ctrl-c -
require 'sinatra' require 'rubygems' class testserver < sinatra::application set :port, 22340 '/' "hello world" end run! if app_file == $0 end
very simple application ruby 2.0.0-p0 , sinatra 1.4.2
when ctrl-c webrick server restarts on default port... see output below
lm-bos-00715009:server joshughes$ ruby test.rb [2013-04-19 16:07:48] info webrick 1.3.1 [2013-04-19 16:07:48] info ruby 2.0.0 (2013-02-24) [x86_64-darwin11.4.2] == sinatra/1.4.2 has taken stage on 22340 development backup webrick [2013-04-19 16:07:48] info webrick::httpserver#start: pid=63798 port=22340 ^c == sinatra has ended set (crowd applauds) [2013-04-19 16:07:56] info going shutdown ... [2013-04-19 16:07:56] info webrick::httpserver#start done. [2013-04-19 16:07:56] info webrick 1.3.1 [2013-04-19 16:07:56] info ruby 2.0.0 (2013-02-24) [x86_64-darwin11.4.2] == sinatra/1.4.2 has taken stage on 4567 development backup webrick [2013-04-19 16:07:56] info webrick::httpserver#start: pid=63798 port=4567 ^c
can me on might going wrong here?
the problem you’re not correctly using sinatra modular style. rather requiring sinatra
, inheriting sinatra::application
should require sinatra/base
, inherit sinatra::base
.
what’s happening this. require plain sinatra
, in turn requires sinatra/main
. file adds at_exit
handler runs built in server (unless disable it). explicitly call run!
in own code, server starts because of call, when exit at_exit
handler starts server again. requiring sinatra/base
doesn’t start built-in server @ exit, you’ll have own explicit call run!
.
require 'sinatra/base' # change here require 'rubygems' class testserver < sinatra::base # , here set :port, 22340 '/' "hello world" end run! if app_file == $0 end
Comments
Post a Comment