summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-20 14:03:04 -0700
committerDouwe Maan <douwe@gitlab.com>2015-08-20 14:03:04 -0700
commit123af7856167f01ac0a7873bca1ef2cbb835e3b5 (patch)
tree22f6ec3e3be51e6e6d2402788fb2dd19ed792f1d /lib
parent48e25a019a7dacbadeb3a49ed96e41d2c2241feb (diff)
downloadgitlab-ce-123af7856167f01ac0a7873bca1ef2cbb835e3b5.tar.gz
Add gitlab:reply_by_email:check rake task.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/reply_by_email.rb9
-rw-r--r--lib/tasks/gitlab/check.rake145
2 files changed, 151 insertions, 3 deletions
diff --git a/lib/gitlab/reply_by_email.rb b/lib/gitlab/reply_by_email.rb
index b6157de3610..61d048fd200 100644
--- a/lib/gitlab/reply_by_email.rb
+++ b/lib/gitlab/reply_by_email.rb
@@ -2,9 +2,12 @@ module Gitlab
module ReplyByEmail
class << self
def enabled?
- config.enabled &&
- config.address &&
- config.address.include?("%{reply_key}")
+ config.enabled && address_formatted_correctly?
+ end
+
+ def address_formatted_correctly?
+ config.address &&
+ config.address.include?("%{reply_key}")
end
def reply_key
diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake
index 80ee572938d..608253d916c 100644
--- a/lib/tasks/gitlab/check.rake
+++ b/lib/tasks/gitlab/check.rake
@@ -2,6 +2,7 @@ namespace :gitlab do
desc "GitLab | Check the configuration of GitLab and its environment"
task check: %w{gitlab:gitlab_shell:check
gitlab:sidekiq:check
+ gitlab:reply_by_email:check
gitlab:ldap:check
gitlab:app:check}
@@ -577,6 +578,150 @@ namespace :gitlab do
end
end
+
+ namespace :reply_by_email do
+ desc "GitLab | Check the configuration of Reply by email"
+ task check: :environment do
+ warn_user_is_not_gitlab
+ start_checking "Reply by email"
+
+ if Gitlab.config.reply_by_email.enabled
+ check_address_formatted_correctly
+ check_mail_room_config_exists
+ check_imap_authentication
+ check_initd_configured_correctly
+ check_mail_room_running
+ else
+ puts 'Reply by email is disabled in config/gitlab.yml'
+ end
+
+ finished_checking "Reply by email"
+ end
+
+
+ # Checks
+ ########################
+
+ def check_address_formatted_correctly
+ print "Address formatted correctly? ... "
+
+ if Gitlab::ReplyByEmail.address_formatted_correctly?
+ puts "yes".green
+ else
+ puts "no".red
+ try_fixing_it(
+ "Make sure that the address in config/gitlab.yml includes the '%{reply_key}' placeholder."
+ )
+ fix_and_rerun
+ end
+ end
+
+ def check_initd_configured_correctly
+ print "Init.d configured correctly? ... "
+
+ path = "/etc/default/gitlab"
+
+ if File.exist?(path) && File.read(path).include?("mail_room_enabled=true")
+ puts "yes".green
+ else
+ puts "no".red
+ try_fixing_it(
+ "Enable mail_room in the init.d configuration."
+ )
+ for_more_information(
+ "doc/reply_by_email/README.md"
+ )
+ fix_and_rerun
+ end
+ end
+
+ def check_mail_room_running
+ print "MailRoom running? ... "
+
+ path = "/etc/default/gitlab"
+
+ unless File.exist?(path) && File.read(path).include?("mail_room_enabled=true")
+ puts "can't check because of previous errors".magenta
+ return
+ end
+
+ if mail_room_process_count > 0
+ puts "yes".green
+ else
+ puts "no".red
+ try_fixing_it(
+ sudo_gitlab("RAILS_ENV=production bin/mail_room start")
+ )
+ for_more_information(
+ see_installation_guide_section("Install Init Script"),
+ "see log/mail_room.log for possible errors"
+ )
+ fix_and_rerun
+ end
+ end
+
+ def check_mail_room_config_exists
+ print "MailRoom config exists? ... "
+
+ mail_room_config_file = Rails.root.join("config", "mail_room.yml")
+
+ if File.exists?(mail_room_config_file)
+ puts "yes".green
+ else
+ puts "no".red
+ try_fixing_it(
+ "Copy config/mail_room.yml.example to config/mail_room.yml",
+ "Check that the information in config/mail_room.yml is correct"
+ )
+ for_more_information(
+ "doc/reply_by_email/README.md"
+ )
+ fix_and_rerun
+ end
+ end
+
+ def check_imap_authentication
+ print "IMAP server credentials are correct? ... "
+
+ mail_room_config_file = Rails.root.join("config", "mail_room.yml")
+
+ unless File.exists?(mail_room_config_file)
+ puts "can't check because of previous errors".magenta
+ return
+ end
+
+ config = YAML.load_file(mail_room_config_file)[:mailboxes].first rescue nil
+
+ if config
+ begin
+ imap = Net::IMAP.new(config[:host], port: config[:port], ssl: config[:ssl])
+ imap.login(config[:email], config[:password])
+ connected = true
+ rescue
+ connected = false
+ end
+ end
+
+ if connected
+ puts "yes".green
+ else
+ puts "no".red
+ try_fixing_it(
+ "Check that the information in config/mail_room.yml is correct"
+ )
+ for_more_information(
+ "doc/reply_by_email/README.md"
+ )
+ fix_and_rerun
+ end
+ end
+
+ def mail_room_process_count
+ ps_ux, _ = Gitlab::Popen.popen(%W(ps ux))
+ ps_ux.scan(/mail_room \d+\.\d+\.\d+/).count
+ end
+ end
+
namespace :ldap do
task :check, [:limit] => :environment do |t, args|
# Only show up to 100 results because LDAP directories can be very big.