Commit 123af785 authored by Douwe Maan's avatar Douwe Maan

Add gitlab:reply_by_email:check rake task.

parent 48e25a01
...@@ -93,6 +93,12 @@ In this example, we'll use the Gmail address `gitlab-replies@gmail.com`. If you' ...@@ -93,6 +93,12 @@ In this example, we'll use the Gmail address `gitlab-replies@gmail.com`. If you'
sudo service gitlab restart sudo service gitlab restart
``` ```
7. Check if everything is configured correctly
```sh
sudo bundle exec rake gitlab:reply_by_email:check RAILS_ENV=production
```
8. Reply by email should now be working. 8. Reply by email should now be working.
Note: If you're running GitLab in development mode and using `foreman`, make sure to also uncomment the `mail_room` line in your `Procfile`. Note: If you're running GitLab in development mode and using `foreman`, make sure to also uncomment the `mail_room` line in your `Procfile`.
......
...@@ -2,9 +2,12 @@ module Gitlab ...@@ -2,9 +2,12 @@ module Gitlab
module ReplyByEmail module ReplyByEmail
class << self class << self
def enabled? def enabled?
config.enabled && config.enabled && address_formatted_correctly?
config.address && end
config.address.include?("%{reply_key}")
def address_formatted_correctly?
config.address &&
config.address.include?("%{reply_key}")
end end
def reply_key def reply_key
......
...@@ -2,6 +2,7 @@ namespace :gitlab do ...@@ -2,6 +2,7 @@ namespace :gitlab do
desc "GitLab | Check the configuration of GitLab and its environment" desc "GitLab | Check the configuration of GitLab and its environment"
task check: %w{gitlab:gitlab_shell:check task check: %w{gitlab:gitlab_shell:check
gitlab:sidekiq:check gitlab:sidekiq:check
gitlab:reply_by_email:check
gitlab:ldap:check gitlab:ldap:check
gitlab:app:check} gitlab:app:check}
...@@ -577,6 +578,150 @@ namespace :gitlab do ...@@ -577,6 +578,150 @@ namespace :gitlab do
end end
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 namespace :ldap do
task :check, [:limit] => :environment do |t, args| task :check, [:limit] => :environment do |t, args|
# Only show up to 100 results because LDAP directories can be very big. # Only show up to 100 results because LDAP directories can be very big.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment