Commit 154c9b4e authored by egarcia's avatar egarcia

first attempt at sending emails

parent 905ad819
......@@ -69,6 +69,12 @@ SSH_USERS = {
'production' => 'egarcia'
}
f = File.open('smtp.yml')
SMTP = YAML::load( f )
f.close
puts SMTP.inspect
# =========== END OF CUSTOMIZABLE SETTINGS =============
# Server urls. Used for obtaining the list of svn repositories
......@@ -117,8 +123,27 @@ def repository_exists?(repository)
local_repository_list.include? repository
end
def shell(command)
def send_email(subject, body)
Pony.mail(
:to => ['to'],
:subject => "Error in OHWR backup: #{subject}",
:body => body,
:via => :smtp,
:attachments => [],
:via_options => {
:address => SMTP['server'],
:port => SMTP['port'],
:enable_starttls_auto => true,
:user_name => SMTP['user_name'],
:password => SMTP['password'],
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
:domain => SMTP['domain'] # the HELO domain provided by the client to the server
}
)
end
def shell(command)
err = StringIO.new
status = Open4::popen4(command) do |pid, stdin, stdout, stderr|
......@@ -128,6 +153,7 @@ def shell(command)
if status.exitstatus == 0 then
log "#{command} - ok"
else
send_email("(#{status.exitstatus}) - #{command}", err.string)
fail("Command failed(#{status.exitstatus}) - #{command}:\n#{err.string}")
end
end
......@@ -181,7 +207,7 @@ namespace :backup do
task :prepare_folders do
title "Preparing local folders"
[LOCAL_REPOSITORY_PATH, LOCAL_GIT_PATH, LOCAL_DB_PATH, LOCAL_FILES_PATH, File.join(LOCAL_SYMPA_PATH,'arc'), File.join(LOCAL_SYMPA_PATH,'list_data')].each do |path|
shell "mkdir -p #{path}"
shell "mkdir #{path}"
end
end
......
to: 'egarcia@splendeo.es'
server: 'smtp.gmail.com'
port: '587'
user_name: 'contact@splendeo.es'
password: 'secret'
domain: 'splendeo.es'
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