0
-# WARNING: this config file has not been tested yet.
0
-# If you know God better then I, feel free to tweak it and send it to me.
0
+# http://god.rubyforge.org/
0
+# Config file for god that configures watches for each instance of a thin server for
0
+# each thin configuration file found in /etc/thin.
0
+# In order to get it working on Ubuntu, I had to make a change to god as noted at
0
+# http://blog.alexgirard.com/2007/10/25/ruby-one-line-to-save-god/
0
-
RAILS_ROOT = "/Users/marc/projects/refactormycode"
0
+
config_path = "/etc/thin"
0
- w.interval = 5.seconds # default
0
- w.start = "thin start -c #{RAILS_ROOT} -P #{RAILS_ROOT}/tmp/pids/thin.3000.pid -p 3000 -d"
0
- w.stop = "thin stop -P #{RAILS_ROOT}/tmp/pids/thin.3000.pid"
0
- w.restart = "thin restart -P #{RAILS_ROOT}/tmp/pids/thin.3000.pid -p 3000"
0
- w.pid_file = File.join(RAILS_ROOT, "tmp/pids/thin.3000.pid")
0
- # clean pid files before start if necessary
0
- w.behavior(:clean_pid_file)
0
- # determine the state on startup
0
- w.transition(:init, { true => :up, false => :start }) do |on|
0
- on.condition(:process_running) do |c|
0
- # determine when process has finished starting
0
- w.transition([:start, :restart], :up) do |on|
0
- on.condition(:process_running) do |c|
0
- on.condition(:tries) do |c|
0
+Dir[config_path + "/*.yml"].each do |file|
0
+ config = YAML.load_file(file)
0
+ num_servers = config["servers"] ||= 1
0
- # start if process is not running
0
- w.transition(:up, :start) do |on|
0
- on.condition(:process_exits)
0
- # restart if memory or cpu is too high
0
- w.transition(:up, :restart) do |on|
0
- on.condition(:memory_usage) do |c|
0
- c.above = 50.megabytes
0
- on.condition(:cpu_usage) do |c|
0
- on.condition(:flapping) do |c|
0
- c.to_state = [:start, :restart]
0
- c.transition = :unmonitored
0
- c.retry_in = 10.minutes
0
- c.retry_within = 2.hours
0
+ for i in 0...num_servers
0
+ w.group = "thin-" + File.basename(file, ".yml")
0
+ w.name = w.group + "-#{i}"
0
+ w.interval = 30.seconds
0
+ w.uid = config["user"]
0
+ w.gid = config["group"]
0
+ w.start = "thin start -C #{file} -o #{i}"
0
+ w.start_grace = 10.seconds
0
+ w.stop = "thin stop -C #{file} -o #{i}"
0
+ w.stop_grace = 10.seconds
0
+ w.restart = "thin restart -C #{file} -o #{i}"
0
+ pid_path = config["chdir"] + "/" + config["pid"]
0
+ ext = File.extname(pid_path)
0
+ w.pid_file = pid_path.gsub(/#{ext}$/, ".#{i}#{ext}")
0
+ w.behavior(:clean_pid_file)
0
+ start.condition(:process_running) do |c|
0
+ c.interval = 5.seconds
0
+ w.restart_if do |restart|
0
+ restart.condition(:memory_usage) do |c|
0
+ c.above = 150.megabytes
0
+ c.times = [3,5] # 3 out of 5 intervals
0
+ restart.condition(:cpu_usage) do |c|
0
+ on.condition(:flapping) do |c|
0
+ c.to_state = [:start, :restart]
0
+ c.transition = :unmonitored
0
+ c.retry_in = 10.minutes
0
+ c.retry_within = 2.hours