16

I have simple Sinatra app.

web.rb:

require 'sinatra'

get '/' do 
    "Hello" 
end

Gemfile:*

source :rubygems

gem 'sinatra', '1.1.0'
gem 'thin', '1.2.7'

config.ru:

require './web'
run Sinatra::Application

But when I deploy my app on Heroku I'll get the error on logs:

2012-03-27T19:17:48+00:00 heroku[router]: Error H14 (No web processes running) -> GET furious-waterfall-6586.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=

How can I fix it?

Eric Wendelin
  • 43,147
  • 9
  • 68
  • 92
ceth
  • 44,198
  • 62
  • 180
  • 289

5 Answers5

25

Here's how to create a minimal sinatra app that deploys to heroku:

app.rb:

require 'sinatra'

get '/' do
  "hello world"
end

Gemfile:

source 'https://rubygems.org'

gem 'heroku'
gem 'sinatra'
gem 'thin'

config.ru:

require './app'
run Sinatra::Application

Type these commands in your command line to deploy (without the $ signs):

$ bundle install
$ git init
$ git add -f app.rb Gemfile Gemfile.lock config.ru
$ git commit -am "initial commit"
$ heroku create <my-app-name>
$ git push heroku master

Then test your app:

$ curl <my-app-name>.heroku.com

and you should see:

hello world
Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168
  • I got this error when trying the above "The source :rubygems is deprecated because HTTP requests are insecure. Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not." – JGallardo Aug 10 '13 at 01:02
  • @JGallardo, thanks for your comment! Bundler wants you to use HTTPS instead of HTTP, so you just have to change the line `source :rubygems` to `source 'https://rubygems.org'`. I changed that in my answer as well. Cheers – Patrick Oscity Aug 11 '13 at 13:21
  • The `heroku` gem is now deprecated (replaced by the Heroku Toolbelt). More info here: https://devcenter.heroku.com/articles/getting-started-with-ruby – ben.snape Jul 23 '14 at 14:29
16

You need a Procfile file alongside your config.ru to tell Heroku how to run your app. Here is the content of an example Procfile:

web: bundle exec ruby web.rb -p $PORT

Heroku Ruby docs on Procfiles

EDIT: Here's a sample config.ru from one of my sinatra/Heroku apps:

$:.unshift File.expand_path("../", __FILE__)
require 'rubygems'
require 'sinatra'
require './web'
run Sinatra::Application

You may need to require sinatra and rubygems for it to work.

Boguslaw
  • 130
  • 8
Eric Wendelin
  • 43,147
  • 9
  • 68
  • 92
  • @demas I've added a sample config.ru file in case that helps. Your Gemfile looks solid (though that is a kinda old version of sinatra, not sure if that plays in at all) – Eric Wendelin Mar 27 '12 at 20:32
  • Can you pls create minimal Sinatra-app on Github? I have tried your changes, but it doesn't help me – ceth Mar 27 '12 at 20:35
  • Sure, I'll spin one up in a few hours if you don't get it figured by then. Sorry, my sinatra apps thus far have been closed source :(( – Eric Wendelin Mar 27 '12 at 20:47
  • 1
    You might find this sinatra-bootstrap project useful in the meantime: https://github.com/adambair/sinatra-bootstrap – Eric Wendelin Mar 27 '12 at 20:49
  • 1
    as far as i know a Procfile should not be needed. – Patrick Oscity Mar 27 '12 at 21:23
  • You do not need the Procfile, unless you wish to run a webserver other than Webrick. Check out `heroku ps` and you can see what command was executed by Heroku to run your app! – danielricecodes Jun 26 '14 at 17:07
10

I have had this problem a number of times in the past, and it was all because I didn't include my config.ru file with the requiring of [app].rb & then pushing to Heroku. Even if I added it afterwards and restarted, Heroku would never pick it up.

  • Destroy your small app on Heroku's site (http://www.heroku.com)
  • Then remove the remote from your project folder

    $ git remote rm heroku
    
  • Then recreate the app

Alex M
  • 2,756
  • 7
  • 29
  • 35
rpearce
  • 1,720
  • 1
  • 21
  • 29
1

As an update, here is a slightly more minimal app that I created, and confirmed to be working as of today. The thin gem was not needed, and a Procfile was not needed to get an initial working app.

Gemfile

source 'https://rubygems.org'
gem 'sinatra'

config.ru

require './app'

run Sinatra::Application

Note: The require line uses './app' instead of 'app'.

app.rb

require 'sinatra'

get '/' do
  'Hello, World! Find me in app.rb'
end

If you want to use this template, you can copy it, bundle, and push the Git repo.

$ git init
$ git add .
$ git commit -m "initial sinatra app"
$ bundle
$ git add Gemfile.lock
$ git commit -m "bundle install"
$ heroku create
$ git push heroku master
$ heroku open
sealocal
  • 10,897
  • 3
  • 37
  • 50
0

By adding the gem 'heroku' to the Gemfile, I got it working. No Procfile needed.

coderberry
  • 3,040
  • 3
  • 26
  • 28