Skip to content

Instantly share code, notes, and snippets.

@pcreux
Last active December 11, 2023 20:24

Revisions

  1. pcreux revised this gist Jul 28, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addons.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@ Free addons!
    heroku addons:add memcachier
    heroku addons:add mandrill:starter
    heroku addons:add newrelic
    heroku addons:add pgbackups
    heroku addons:add pgbackups:auto-month
    heroku addons:add papertrail
    ```
  2. pcreux revised this gist Jul 21, 2014. 3 changed files with 37 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion Gemfile
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    group :production do
    gem 'passenger'
    gem 'unicorn'

    # Enable gzip compression on heroku, but don't compress images.
    gem 'heroku-deflater'
    2 changes: 1 addition & 1 deletion Procfile
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    web: bundle exec passenger start -p $PORT --max-pool-size 3
    web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
    35 changes: 35 additions & 0 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    # config/unicorn.rb

    worker_processes 3
    timeout 30
    preload_app true

    before_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    Rails.logger.info('Disconnected from ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis.quit
    Rails.logger.info('Disconnected from Redis')
    end

    sleep 1
    end

    after_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Rails.logger.info('Connected to ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis = ENV['REDIS_URI']
    Rails.logger.info('Connected to Redis')
    end
    end
  3. pcreux revised this gist May 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion production.rb
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@
    :entitystore => client
    }

    # Send emails via sendgrid
    # Send emails via mandrill

    ActionMailer::Base.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
  4. pcreux revised this gist Feb 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion production.rb
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@

    client = Dalli::Client.new(ENV["MEMCACHIER_SERVERS"],
    :value_max_bytes => 10485760,
    :expires_in => 1.day)
    :expires_in => 86400) # 1 day

    # Configure rack-cache for using memcachier
    config.action_dispatch.rack_cache = {
  5. pcreux revised this gist Feb 22, 2014. 2 changed files with 6 additions and 5 deletions.
    2 changes: 1 addition & 1 deletion addons.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ Free addons!

    ```
    heroku addons:add memcachier
    heroku addons:add sendgrid
    heroku addons:add mandrill:starter
    heroku addons:add newrelic
    heroku addons:add pgbackups
    heroku addons:add papertrail
    9 changes: 5 additions & 4 deletions production.rb
    Original file line number Diff line number Diff line change
    @@ -21,14 +21,15 @@
    }

    # Send emails via sendgrid

    ActionMailer::Base.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
    :address => 'smtp.sendgrid.net',
    :address => 'smtp.mandrillapp.com',
    :port => '587',
    :authentication => :plain,
    :user_name => ENV['SENDGRID_USERNAME'],
    :password => ENV['SENDGRID_PASSWORD'],
    :user_name => ENV['MANDRILL_USERNAME'],
    :password => ENV['MANDRILL_APIKEY'],
    :domain => 'heroku.com',
    :enable_starttls_auto => true
    }

    # ...
  6. pcreux revised this gist Feb 22, 2014. 3 changed files with 2 additions and 37 deletions.
    2 changes: 1 addition & 1 deletion Gemfile
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    group :production do
    gem 'unicorn'
    gem 'passenger'

    # Enable gzip compression on heroku, but don't compress images.
    gem 'heroku-deflater'
    2 changes: 1 addition & 1 deletion Procfile
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
    web: bundle exec passenger start -p $PORT --max-pool-size 3
    35 changes: 0 additions & 35 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -1,35 +0,0 @@
    # config/unicorn.rb

    worker_processes 3
    timeout 30
    preload_app true

    before_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    Rails.logger.info('Disconnected from ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis.quit
    Rails.logger.info('Disconnected from Redis')
    end

    sleep 1
    end

    after_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Rails.logger.info('Connected to ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis = ENV['REDIS_URI']
    Rails.logger.info('Connected to Redis')
    end
    end
  7. pcreux revised this gist Nov 27, 2013. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions addons.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    Free addons!

    ```
    heroku addons:add memcachier
    heroku addons:add sendgrid
    heroku addons:add newrelic
    heroku addons:add pgbackups
    heroku addons:add papertrail
    ```
  8. pcreux revised this gist Nov 27, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ end

    gem 'memcachier'
    gem 'dalli'
    # Fast IO for memcache
    gem 'kgio'

    # Serve static assets through Rack + Memcache
  9. pcreux revised this gist Nov 27, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions production.rb
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@

    # Enable Rails's static asset server for Heroku
    config.serve_static_assets = true

    # Set static assets cache header. rack-cache will cache those.
    config.static_cache_control = "public, max-age=31536000"

    config.cache_store = :dalli_store
    @@ -12,11 +14,13 @@
    :value_max_bytes => 10485760,
    :expires_in => 1.day)

    # Configure rack-cache for using memcachier
    config.action_dispatch.rack_cache = {
    :metastore => client,
    :entitystore => client
    }

    # Send emails via sendgrid
    config.action_mailer.smtp_settings = {
    :address => 'smtp.sendgrid.net',
    :port => '587',
  10. pcreux revised this gist Nov 27, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,17 @@
    group :production do
    gem 'unicorn'

    # Enable gzip compression on heroku, but don't compress images.
    gem 'heroku-deflater'

    # Heroku injects it if it's not in there already
    gem 'rails_12factor'
    end

    gem 'memcachier'
    gem 'dalli'
    gem 'kgio'

    # Serve static assets through Rack + Memcache
    # https://devcenter.heroku.com/articles/rack-cache-memcached-rails31
    gem 'rack-cache'
  11. pcreux renamed this gist Nov 27, 2013. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions config/environments/production.rb → production.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    Refuge::Application.configure do
    # config/environments/production.rb

    # ...

    # Enable Rails's static asset server for Heroku
    config.serve_static_assets = true
    config.static_cache_control = "public, max-age=31536000"
    @@ -23,4 +26,6 @@
    :domain => 'heroku.com',
    :enable_starttls_auto => true
    }
    end

    # ...

  12. pcreux renamed this gist Nov 27, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions config/unicorn.rb → unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # config/unicorn.rb

    worker_processes 3
    timeout 30
    preload_app true
  13. pcreux revised this gist Nov 27, 2013. 2 changed files with 34 additions and 0 deletions.
    1 change: 1 addition & 0 deletions Procfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
    33 changes: 33 additions & 0 deletions config/unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    worker_processes 3
    timeout 30
    preload_app true

    before_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    Rails.logger.info('Disconnected from ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis.quit
    Rails.logger.info('Disconnected from Redis')
    end

    sleep 1
    end

    after_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Rails.logger.info('Connected to ActiveRecord')
    end

    # If you are using Redis but not Resque, change this
    if defined?(Resque)
    Resque.redis = ENV['REDIS_URI']
    Rails.logger.info('Connected to Redis')
    end
    end
  14. pcreux revised this gist Nov 27, 2013. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions config/environments/production.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    Refuge::Application.configure do
    # Enable Rails's static asset server for Heroku
    config.serve_static_assets = true
    config.static_cache_control = "public, max-age=31536000"

    config.cache_store = :dalli_store

    client = Dalli::Client.new(ENV["MEMCACHIER_SERVERS"],
    :value_max_bytes => 10485760,
    :expires_in => 1.day)

    config.action_dispatch.rack_cache = {
    :metastore => client,
    :entitystore => client
    }

    config.action_mailer.smtp_settings = {
    :address => 'smtp.sendgrid.net',
    :port => '587',
    :authentication => :plain,
    :user_name => ENV['SENDGRID_USERNAME'],
    :password => ENV['SENDGRID_PASSWORD'],
    :domain => 'heroku.com',
    :enable_starttls_auto => true
    }
    end
  15. pcreux created this gist Nov 27, 2013.
    11 changes: 11 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    group :production do
    gem 'unicorn'
    gem 'heroku-deflater'
    gem 'rails_12factor'
    end

    gem 'memcachier'
    gem 'dalli'
    gem 'kgio'

    gem 'rack-cache'