Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get turnout to work on heroku #34

Open
luisbraga opened this issue Mar 19, 2016 · 5 comments
Open

Can't get turnout to work on heroku #34

luisbraga opened this issue Mar 19, 2016 · 5 comments
Assignees
Labels

Comments

@luisbraga
Copy link

Is anyone else having trouble using turnout on heroku?
I've just created a new app and deployed it but it only works locally.

This is my gemfile

source 'https://rubygems.org'
ruby '2.2.2'

gem 'rails', '4.2.5.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'turnout'

group :development, :test do
  gem 'sqlite3'
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

And here is turnout.rb in config/initializers


Turnout.configure do |config|
  config.app_root = '.'
  config.named_maintenance_file_paths = {default: config.app_root.join('tmp', 'maintenance.yml').to_s}
  config.default_maintenance_page = Turnout::MaintenancePage::HTML
  config.default_reason = "The site is temporarily down for maintenance.\nPlease check back soon."
  config.default_allowed_paths = []
  config.default_response_code = 503
  config.default_retry_after = 7200
end

maintenance.yml is created when running rake maintenance:start and is deleted on maintenance:end
Still not working. Am I missing something?

Thanks in advance.

@adamcrown
Copy link
Collaborator

Hmm, I just pushed up a test app to Heroku and I'm seeing the same thing. It works locally in development but not in production. I'll see if I can dig into it and figure out what's going on.

@adamcrown adamcrown added the bug label Mar 20, 2016
@adamcrown adamcrown self-assigned this Mar 20, 2016
@adamcrown
Copy link
Collaborator

Okay, so I think I know what's going on here. Turnout works by writing a tmp/maintenance.yml file. Because Heroku starts up a new dyno to run rake tasks it's not writing the file anywhere that the web dyno can find it.

The only way I found to get this to work is to create a web endpoint to start and stop maintenance mode

class MaintenancesController < ApplicationController
  def start
    Turnout::MaintenanceFile.default.write
    render text: 'Maintenance mode on'
  end

  def end
    Turnout::MaintenanceFile.default.delete
    render text: 'Maintenance mode off'
  end
end

Of course if you do this you should authenticate those requests somehow. Also make sure you allow the path to that controller in Turnout config. Otherwise you'll never be able to turn maintenance mode off.

Turnout.configure do |config|
  config.default_allowed_paths = ['/maintenance']
end

It wouldn't be hard to trigger it with an environment variable, but it would require restarting the web server. I've had at least one other person request that there be a Redis backend or similar that could be used to enable and disable maintenance mode. That would require some work, but it's doable.

All that to say, you may just want to stick with Heroku's own maintenance mode.

@luisbraga
Copy link
Author

Thanks for taking your time testing and providing an alternative.
I'll probably stick with Heroku's approach. Too bad there's no option for allowed ips.

@ncri
Copy link

ncri commented Jun 10, 2019

Using an env var rather than a temp file is crucial in many environments, not only on Heroku. We use Kubernetes and have the same issue, as multiple pods with their own file system are running our app. Switching maintenance mode on will only work as long as requests go into the server instances that have the file. And also a restart or deploy will exit maintenance mode.

@adamcrown
Copy link
Collaborator

Thanks for the input @ncri. I'd be happy to support an environment variable if it can be integrated in a clean way. I'll go ahead and reopen this issue as a placeholder. I'd certainly be happy to accept a pull request from anybody who wants to accept it. In the mean time, I can't commit to any timeframe, but I'd be happy to add this as a feature myself whenever I am able.

@adamcrown adamcrown reopened this Jun 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants