Running Sinatra app with Mongrel on Windows - ruby

I'd like to start a Sinatra app from Mongrel on Windows, rather than Sinatra starting Mongrel in the background.
Is there a simple way to use Mongrel for Sinatra? It's looking for a rails app by default.
Edit: Suggested solution is to simply run a VMWare or SunBox with real Linux and deal with the corporate issues that way.

Check out http://sinatra-book.gittr.com/.
FastCGI is the chapter you're looking for within the page, because that's what mongrel is

if you have a rake config, like config.ru
then install thin gem
then
thin -p 3000 -r config.ru
I think.
-r

Related

How can I run dashing with ruby web server puma?

Dashing uses thin ruby web server as default.
I'm trying to used puma as my ruby web server since I got issue with memory consumption with the default web server.
I have read in some github forums that the rufus-scheduler which is used to schedule jobs might be the cause of memory issue.
I set up gem 'puma' in mg GemFile & bundled it.
But every time I run my application, it uses thin web server again.
dashing start
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 0.0.0.0:3030, CTRL+C to stop
Please help on how to properly use puma web server on dashing.
Run your server using puma:
puma config.ru
Or run your server with rackup and specify puma as the server:
bundle exec rackup -s puma -p 3030
Explanation:
When you run dashing start, you're using the dashing CLI tool. The reason you can't run dashing with puma using the dashing CLI tool is because the use of thin is hard-coded. See the dashing CLI code.

sinatra hello world app doesn't work

I'm having trouble learning how to use Sinatra.
Versions are
Mac OSX 10.11.2
Ruby 2.2.2
Sinatra 1.4.6
I wrote the same code as the first code in this site.
# main.rb
require 'sinatra'
get '/' do
'Hello world!'
end
Then I tried a command in the same derectory
% ruby main.rb
== Sinatra (v1.4.6) has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
Then I accessed http://localhost:4567 with Google Chrome, but the browser didn't recieve any data (ERR_EMPTY_RESPONSE). Also nothing logged in Terminal.
I tried other port (like 3000) by -p option, but it didn't work.
What am I doing wrong?
I updated gem and reinstalled sinatra, then it worked.
gem update --system
gem uninstall sinatra
gem install sinatra

How does thin magically "take over" when included in the gemfile/required in the app?

I gem "thin" and require 'thin' are added to any (seems like) Rack app, it will automatically be chosen when the app is launched via rackup, instead of WEBrick.
How does rackup know to use thin? What if I use unicorn or Puma or something else?
Rack's source code states has three default servers in the following order: Thin, Puma and WEBrick.
Rack will attempt to 'mount' these three servers unless the PHP_FCGI_CHILDREN or RACK_HANDLER environment variables are set.
This behavior might change in the future, but for now only thin and puma will be recognized automatically when their gems are included.

Can I do Sinatra program without restart server?

When I modify the code and have to restart server to see results. Have any way out?
There are a few options, detailed in the Sinatra FAQ. The simplest appears to be to use shotgun, which you can install and invoke as follows:
$ sudo gem install shotgun
$ shotgun myapp.rb
or if you use define your app by inheriting from Sinatra::Base and use a config.ru file:
$ shotgun config.ru -p 4567
If you use Phusion Passenger, you can put this file in the application’s root folder
tmp/always_restart.txt
and it will restart on every request.
http://www.modrails.com/documentation/Users%20guide%20Apache.html ( section 8.7 )
Better way is to use reloader from sinatra-contrib gem (also from Sinatra FAQ): First install sinatra-contrib gem, then ensure your application .rb file starts with these lines:
require 'sinatra'
require 'sinatra/reloader' if development?
And then any modified config files will be reloaded (no need to restart server!)

Which HTTP web server can I use to debug ruby code using Rubymine 3.0.1?

I've being using Mongrel with Rails 2.3.X and Ruby 1.8.7 without problems, but when I switch to Ruby 1.9.2 and Rails 3, I'm having problems with mongrel to debug.
Webrick is just slow, so, do you know any alternatives?
Do you know how to fix mongrel to successfully debug rails app using rubymine 3.0.1?
RubyMine 3.1 is out now and supports a number of different servers. Under the "Run" menu, select "Edit Configurations" then go to "Defaults->Rails". There you can choose between:
WEBrick
lighttpd
mongrel
thin
trinidad
unicorn
glassfish
I couldn't get Defaults->Rails changes to affect my different configs that were set to 'Default', but I did have success changing the discrete config ('development') directly. Note: For Mongrel you need to have this in your gemfile:
gem 'mongrel', '1.2.0.pre2'
I'm using RM 3.1.1, Rails 3.0.9 and Ruby 1.9.2.

Resources