Search code examples
ruby-on-railsibm-cloud

Bluemix issue on rails: Instance (index 0) failed to start accepting connections


I am trying to deploy a small Rails app to Bluemix. It works fine locally. The error I get is:

Instance (index 0) failed to start accepting connections
2015-12-13T20:57:11.571-0800[API/2]OUTApp instance exited with guid
 68527a7d-ee7c-40a9-a500-0b44c01d267c payload: 
{"cc_partition"=>"default", 
"droplet"=>"68527a7d-ee7c-40a9-a500-0b44c01d267c", 
"version"=>"3b480d7d-3483-435b-bbfc-b4682a9994e2", 
"instance"=>"faed828f09364ac79a32503deaace288", "index"=>0, 
"reason"=>"CRASHED", "exit_status"=>-1, 
"exit_description"=>"failed to accept connections within health check timeout", 
"crash_timestamp"=>1450069031}

All the answers I found so far say that this is a port issue, and also when I deploy using

cf push <myapp> --no-route

it goes fine, i.e. no error messages.

I use puma as a server and my Procfile (with that spelling and it is the root) has

web: bundle exec puma -p $PORT 

Even with that, Bluemix starts puma, but always with port 3000. Even when I put something like

web: bundle exec puma -p 1234

it starts with port 3000. So it seems to be ignoring the Procfile. What am I doing wrong?

Per Jeff's question below, my buildpack is ruby 1.6.7, and this is my Gemfile:

source 'https://rubygems.org'

ruby "2.2.2"

gem 'rails', '4.2.1'

gem 'pg'
gem 'activerecord-postgresql-adapter'

gem 'cf-autoconfig', '~> 0.2.1'
gem 'rails_12factor'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read  more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more:    https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'

 # Access an IRB console on exception pages or by using <%= console %> in views
 gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

gem 'devise'

gem 'puma'

And this is the log

2015-12-14T18:52:52.265-0800[STG/116]OUT-----> Uploading droplet (32M)
2015-12-14T18:53:00.626-0800[DEA/116]OUTStarting app instance (index 0) with guid 68527a7d-ee7c-40a9-a500-0b44c01d267c
2015-12-14T18:53:08.174-0800[App/0]OUT=> Booting Puma
2015-12-14T18:53:08.174-0800[App/0]OUT=> Rails 4.2.1 application starting in production on http://0.0.0.0:3000
2015-12-14T18:53:08.174-0800[App/0]OUT=> Run `rails server -h` for more startup options
2015-12-14T18:53:08.174-0800[App/0]OUT=> Ctrl-C to shutdown server
2015-12-14T18:53:09.038-0800[App/0]OUTPuma 2.15.3 starting...
2015-12-14T18:53:09.038-0800[App/0]OUT* Min threads: 0, max threads: 16
2015-12-14T18:53:09.038-0800[App/0]OUT* Environment: production
2015-12-14T18:53:09.038-0800[App/0]OUT* Listening on tcp://0.0.0.0:3000
2015-12-14T18:54:06.485-0800[DEA/116]ERRInstance (index 0) failed to start accepting connections
2015-12-14T18:54:06.488-0800[App/0]ERR
2015-12-14T18:54:06.487-0800[API/3]OUTApp instance exited with guid 68527a7d-ee7c-40a9-a500-0b44c01d267c payload: 
{"cc_partition"=>"default", "droplet"=>"68527a7d-ee7c-40a9-a500-0b44c01d267c", 
"version"=>"972ea1d8-aaf2-4fa8-a937-fad4024907f7",
"instance"=>"2c0a0d9d83a0442594596b42570ff3b8", "index"=>0, 
"reason"=>"CRASHED", "exit_status"=>-1, 
"exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1450148046}

Thanks for your help!


Solution

  • So the first look you are starting on port 3000. Bluemix/Cloud Foundry assigns you a port to run on. You need the following in your manifest.yml. You will need to swap out the info for your app though. The $PORT tells Ruby to bind to an assigned port from Bluemix.

    ---
    applications:
    #swap out myapp-jbs for your own app name
    - name: myapp-jbs
      memory: 1GB
      instances: 1
      path: .
      command: bundle exec rake db:setup && bundle exec rails s -p $PORT
      services:
      #swap out the below for your own
      #cf cs elephantsql turtle yourownname
        - postgres-myapp
    

    Additionally push your app with the following command.

    cf push -b https://github.com/cloudfoundry/ruby-buildpack.git