· 8 years ago · Mar 03, 2018, 11:10 AM
1require 'rubygems'
2require 'tlsmail'
3
4RAILS_ROOT = "/Users/reggie/src/new_altomic/altomic"
5FETCHER_SCRIPT = "RAILS_ENV=production #{RAILS_ROOT}/script/mailer_daemon_fetcher"
6
7Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
8
9# mail settings
10God::Contacts::Email.message_settings = {
11 :from => 'altomic.mail.test@altomic.com'
12}
13
14God::Contacts::Email.server_settings = {
15 :address => "smtp.gmail.com",
16 :tls => 'true',
17 :port => 587,
18 :domain => 'gmail.com',
19 :user_name => "********@gmail.com",
20 :password => "*******",
21 :authentication => :plain
22}
23
24God.contact(:email) do |c|
25 c.name = 'Andrea Reginato'
26 c.email = 'andrew@mikamai.com'
27 c.group = 'developers'
28end
29
30
31
32# process watching
33God.watch do |w|
34
35 # this is a unique name that can be used also later on
36 # to call some of these commands
37 w.name = "fetcher-daemon"
38 w.interval = 5.seconds
39 w.uid = 'reggie'
40
41 # definition of commands
42 w.start = "#{FETCHER_SCRIPT} start"
43 w.stop = "#{FETCHER_SCRIPT} stop"
44 w.restart = "#{FETCHER_SCRIPT} restart"
45
46 # time to wait after the starting (understand better)
47 w.start_grace = 10.seconds
48 w.restart_grace = 10.seconds
49
50 # (be careful to set the pid file number to the correct name)
51 w.pid_file = File.join(RAILS_ROOT, 'log', 'MailerDaemonFetcherDaemon.pid')
52 w.behavior(:clean_pid_file)
53
54 # At any given time, a Watch will be in one of the init, up, start, or restart states.
55 # As different conditions are satisfied, the Watch will progress from state to state,
56 # enabling and disabling conditions along the way. (READ MORE ON TRANSITION DOC...)
57 # determine the state on startup
58 w.transition(:init, { true => :up, false => :start }) do |on|
59 on.condition(:process_running) do |c|
60 c.running = true
61 end
62 end
63
64 # determine when process has finished starting
65 w.transition([:start, :restart], :up) do |on|
66 on.condition(:process_running) do |c|
67 c.running = true
68 end
69 end
70
71 # start if process is not running
72 w.transition(:up, :start) do |on|
73 on.condition(:process_exits)
74 end
75
76 # # bind the notification via mail when some problems occours
77 w.transition(:up, :start) do |on|
78 on.condition(:process_exits) do |c|
79 c.notify = 'developers'
80 end
81 end
82
83end