Guest User

Untitled

a guest
Apr 30th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. module Bluepill
  2. module Triggers
  3. class EmailNotifier < Bluepill::Trigger
  4. def initialize(process, options = {})
  5. @notify_on = [options.delete(:notify_on)]
  6. super
  7. end
  8.  
  9. def notify(transition)
  10. if @notify_on.include?(transition.to_name)
  11. send_notification(transition)
  12. end
  13. end
  14.  
  15. private
  16.  
  17. def send_notification(transition)
  18. Pony.mail(
  19. :to => Email['recipient'],
  20. :subject => "Your process #{self.process.name}",
  21. :body => "Your process #{self.process.name}",
  22. :content_type => 'text/html',
  23. :via => :smtp,
  24. :smtp => {
  25. :host => "smtp.gmail.com",
  26. :port => "587",
  27. :auth => :plain,
  28. :user => Email['user'],
  29. :password => Email['password'],
  30. :tls => true
  31. }
  32. )
  33. end
  34. end
  35. end
  36. end
  37.  
  38.  
  39. Bluepill.application("bookit") do |app|
  40. app.process("backend_app") do |process|
  41. process.working_dir = ROOT
  42.  
  43. process.start_command = "/usr/bin/env APP_ENV=production script/bookit_ctl start"
  44. process.stop_command = "script/bookit_ctl stop"
  45. process.restart_command = "/usr/bin/env APP_ENV=production script/bookit_ctl restart"
  46.  
  47. process.pid_file = ROOT + "log/bookit.pid"
  48.  
  49. process.restart_grace_time = 10.seconds
  50. process.checks :mem_usage, :every => 5.minutes, :below => 50.megabytes, :times => [3,5]
  51. process.checks :email_notifier, :notify_on => :restarting
  52. end
  53. end
Add Comment
Please, Sign In to add comment