Skip to content

Commit

Permalink
GRN2-xx: Removed Health Check Gem (bigbluebutton#840)
Browse files Browse the repository at this point in the history
* Initial work on removing health check gem

* Added health checks

* Fixed gemfile
  • Loading branch information
farhatahmad authored and jfederico committed Oct 21, 2019
1 parent 9c9867b commit 933408f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 52 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ gem 'http_accept_language'
# Markdown parsing.
gem 'redcarpet'

# For health check endpoint
gem "health_check"

# For limiting access based on user roles
gem 'cancancan', '~> 2.0'

Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ GEM
activesupport (>= 4.2.0)
hashdiff (0.4.0)
hashie (3.6.0)
health_check (3.0.0)
railties (>= 5.0)
hiredis (0.6.3)
http_accept_language (2.1.1)
i18n (1.6.0)
Expand Down Expand Up @@ -363,7 +361,6 @@ DEPENDENCIES
factory_bot_rails
faker
font-awesome-sass (~> 5.9.0)
health_check
hiredis
http_accept_language
i18n-language-mapping (~> 0.1.0)
Expand Down
74 changes: 74 additions & 0 deletions app/controllers/health_check_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frozen_string_literal: true

# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

class HealthCheckController < ApplicationController
skip_before_action :redirect_to_https, :set_user_domain, :set_user_settings, :maintenance_mode?, :migration_error?,
:user_locale, :check_admin_password, :check_user_role

# GET /health_check
def all
response = "success"
@cache_expire = 10.seconds

begin
cache_check
database_check
email_check
rescue => e
response = "Health Check Failure: #{e}"
end

render plain: response
end

private

def cache_check
if Rails.cache.write("__health_check_cache_write__", "true", expires_in: @cache_expire)
raise "Unable to read from cache" unless Rails.cache.read("__health_check_cache_write__") == "true"
else
raise "Unable to write to cache"
end
end

def database_check
if defined?(ActiveRecord)
raise "Database not responding" unless ActiveRecord::Migrator.current_version
end
raise "Pending migrations" unless ActiveRecord::Migration.check_pending!.nil?
end

def email_check
test_smtp if Rails.configuration.action_mailer.delivery_method == :smtp
end

def test_smtp
settings = ActionMailer::Base.smtp_settings

smtp = Net::SMTP.new(settings[:address], settings[:port])
if settings[:enable_starttls_auto] == "true"
smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto)
end

smtp.start(settings[:domain]) do |s|
s.authenticate(settings[:user_name], settings[:password], settings[:authentication])
end
rescue => e
raise "Unable to connect to SMTP Server - #{e}"
end
end
45 changes: 0 additions & 45 deletions config/initializers/health_check.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

Rails.application.routes.draw do
get 'health_check', to: 'health_check/health_check#index'
get '/health_check', to: 'health_check#all'

# Error routes.
match '/401', to: 'errors#unauthorized', via: :all, as: :unauthorized
Expand Down

0 comments on commit 933408f

Please sign in to comment.