How to make thin launch on another port?

I have a very basic test application. When I execute this command, the server ignores the port I specified and runs Thin on port 4567. Why is the port that I specify ignored?

$ruby xxx.rb start -p 8000 == Sinatra/1.3.3 has taken the stage on 4567 for production with backup from Thin >> Thin web server (v1.4.1 codename Chromeo) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:4567, CTRL+C to stop 

xxx.rb file

 require 'Thin' rackup_file = "config.ru" argv = ARGV argv << ["-R", rackup_file ] unless ARGV.include?("-R") argv << ["-e", "production"] unless ARGV.include?("-e") puts argv.flatten Thin::Runner.new(argv.flatten).run! 

config.ru file

 require 'sinatra' require 'sinatra/base' class SingingRain < Sinatra::Base get '/' do return 'hello' end end SingingRain.run! 
+7
source share
3 answers

Your problem is with the line:

 SingingRain.run! 

This is the Sinatras run method, which tells Sinatra to start its own web server, which by default runs on port 4567. This is in your config.ru file, but config.ru is just Ruby, so this line starts as if it was in any other .rb file. This is why you see Sinatra running on this port.

When you stop this server using CTRL-C, Thin will try to continue loading the config.ru file to determine which application to run. In fact, you are not specifying the application in your config.ru , so you will see something like:

 ^C>> Stopping ... == Sinatra has ended his set (crowd applauds) /Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:129:in `to_app': missing run or map statement (RuntimeError) from config.ru:1:in `<main>' ... 

This error simply tells you that you did not actually specify the application to run in your configuration file.

Instead of SingingRain.run! use:

 run SingingRain 

run is a Rack method that indicates which application to run. You can also do run SingingRain.new - Sinatra takes steps so that you can use only the class itself or instance.

The conclusion to this now should only be:

 >> Thin web server (v1.4.1 codename Chromeo) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:8000, CTRL+C to stop 

You will not receive the message == Sinatra/1.3.2 has taken the stage on 4567 for production with backup from Thin , because Sinatra does not start its built-in server, but only your thin server, as you configured it.

+14
source
 #\ -p 8000 

put this at the beginning of config.ru

+16
source

in your config.ru add

set: port => 8000

I would also strongly suggest using Sinatra with something like a passenger + nginx, which does the deployment to produce a breeze. But you should not worry about it if you are going to deploy the hero.

-3
source

All Articles