public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Click here to lend your support to: thin and make a donation at www.pledgie.com !
thin / example / thin.god
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 1 # == God config file
2 # http://god.rubyforge.org/
429ddd75 » macournoyer 2008-02-14 Make god example file work ... 3 # Authors: Gump and michael@glauche.de
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 4 #
5 # Config file for god that configures watches for each instance of a thin server for
6 # each thin configuration file found in /etc/thin.
7 # In order to get it working on Ubuntu, I had to make a change to god as noted at
8 # the following blog:
9 # http://blog.alexgirard.com/2007/10/25/ruby-one-line-to-save-god/
10 #
11 require 'yaml'
1a226855 » macournoyer 2008-01-09 Fix IOError when writing to... 12
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 13 config_path = "/etc/thin"
1a226855 » macournoyer 2008-01-09 Fix IOError when writing to... 14
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 15 Dir[config_path + "/*.yml"].each do |file|
16 config = YAML.load_file(file)
17 num_servers = config["servers"] ||= 1
1a226855 » macournoyer 2008-01-09 Fix IOError when writing to... 18
429ddd75 » macournoyer 2008-02-14 Make god example file work ... 19 (0...num_servers).each do |i|
20 # UNIX socket cluster use number 0 to 2 (for 3 servers)
21 # and tcp cluster use port number 3000 to 3002.
22 number = config['socket'] ? i : (config['port'] + i)
23
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 24 God.watch do |w|
25 w.group = "thin-" + File.basename(file, ".yml")
429ddd75 » macournoyer 2008-02-14 Make god example file work ... 26 w.name = w.group + "-#{number}"
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 27
28 w.interval = 30.seconds
29
30 w.uid = config["user"]
31 w.gid = config["group"]
32
429ddd75 » macournoyer 2008-02-14 Make god example file work ... 33 w.start = "thin start -C #{file} -o #{number}"
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 34 w.start_grace = 10.seconds
35
429ddd75 » macournoyer 2008-02-14 Make god example file work ... 36 w.stop = "thin stop -C #{file} -o #{number}"
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 37 w.stop_grace = 10.seconds
38
429ddd75 » macournoyer 2008-02-14 Make god example file work ... 39 w.restart = "thin restart -C #{file} -o #{number}"
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 40
41 pid_path = config["chdir"] + "/" + config["pid"]
42 ext = File.extname(pid_path)
43
429ddd75 » macournoyer 2008-02-14 Make god example file work ... 44 w.pid_file = pid_path.gsub(/#{ext}$/, ".#{number}#{ext}")
86ca18a9 » macournoyer 2008-02-05 * Add a better sample god c... 45
46 w.behavior(:clean_pid_file)
47
48 w.start_if do |start|
49 start.condition(:process_running) do |c|
50 c.interval = 5.seconds
51 c.running = false
52 end
53 end
54
55 w.restart_if do |restart|
56 restart.condition(:memory_usage) do |c|
57 c.above = 150.megabytes
58 c.times = [3,5] # 3 out of 5 intervals
59 end
60
61 restart.condition(:cpu_usage) do |c|
62 c.above = 50.percent
63 c.times = 5
64 end
65 end
66
67 w.lifecycle do |on|
68 on.condition(:flapping) do |c|
69 c.to_state = [:start, :restart]
70 c.times = 5
71 c.within = 5.minutes
72 c.transition = :unmonitored
73 c.retry_in = 10.minutes
74 c.retry_times = 5
75 c.retry_within = 2.hours
76 end
77 end
1a226855 » macournoyer 2008-01-09 Fix IOError when writing to... 78 end
79 end
80 end