Skip to content

Instantly share code, notes, and snippets.

@traviskroberts
Created May 30, 2015 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save traviskroberts/c1f96cfc74a73316c35b to your computer and use it in GitHub Desktop.
Save traviskroberts/c1f96cfc74a73316c35b to your computer and use it in GitHub Desktop.
# run in non-daemonized mode (so you can monitor it) with `god -c /path/to/mysql.god -D`
# run normally with `god -c /path/to/mysql.god`
# Settings for email notifications (optional)
God::Contacts::Email.defaults do |d|
d.from_email = 'god@my-app.com'
d.from_name = 'God'
d.delivery_method = :smtp # this can also be :sendmail
d.server_host = 'smtp.myapp.com'
d.server_port = 25
d.server_auth = true
d.server_domain = 'myapp.com'
d.server_user = 'smtp_user@myapp.com'
d.server_password = 'password'
end
# you can create as many email entries as you'd like
God.contact(:email) do |c|
c.name = 'me'
c.to_email = 'me@email.com'
end
God.watch do |w|
# you can name this whatever you want
w.name = "mySQL Server"
# polling interval
w.interval = 30.seconds
# command to start service
w.start = "/etc/init.d/mysqld start && /etc/init.d/httpd restart"
# command to stop service
w.stop = "/etc/init.d/mysqld stop"
# command to restart service
w.restart = "/etc/init.d/mysqld restart && /etc/init.d/httpd restart"
# how long to wait after starting service before monitoring resumes
w.start_grace = 20.seconds
# how long to wait after restarting service before monitoring resumes
w.restart_grace = 20.seconds
# location of pid file
w.pid_file = "/var/run/mysqld/mysqld.pid"
# tell god to delete the pid file when mysqld crashes
w.behavior(:clean_pid_file)
# determine the state on startup
w.transition(:init, { true => :up, false => :start }) do |on|
on.condition(:process_running) do |c|
c.running = true
end
end
# determine when process has finished starting
w.transition([:start, :restart], :up) do |on|
on.condition(:process_running) do |c|
c.running = true
end
# failsafe
on.condition(:tries) do |c|
c.times = 8
c.within = 2.minutes
c.transition = :start
end
end
# start if process is not running
w.transition(:up, :start) do |on|
on.condition(:process_exits) do |c|
# send an email to me to notify me that the service has crashed
c.notify = 'me'
end
end
# lifecycle
w.lifecycle do |on|
# If the service keeps triggering a restart over and over, it is considered to be "flapping".
on.condition(:flapping) do |c|
c.to_state = [:start, :restart]
c.times = 5
c.within = 1.minute
c.transition = :unmonitored
# If the service is flapping, wait 10 minutes, then try to start/restart again.
c.retry_in = 10.minutes
c.retry_times = 5
c.retry_within = 2.hours
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment