public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
* Add a better sample god config file in example/thin.god that loads all 
info from config
  files in /etc/thin [Gump].
macournoyer (author)
Tue Feb 05 20:56:22 -0800 2008
commit  86ca18a98098c00fe11ef785f77c3d150a8b13a2
tree    2a226b2b7c9e25afe402b9c6de959562f713f709
parent  d768ff30186e03a0e4167c48cc9d3c6ba55514d8
...
1
 
 
 
 
2
3
4
...
1
2
3
4
5
6
7
8
0
@@ -1,4 +1,8 @@
0
 == 0.6.3 Ninja Cookie release
0
+ * Add a better sample god config file in example/thin.god that loads all info from config
0
+ files in /etc/thin [Gump].
0
+ * Add support for specifying a custom Connector to the server and a more doc about Server
0
+ configuration.
0
  * Add a script to run thin as a system service that can start at startup, closes #31 [Gump]
0
    Setup the service like this:
0
    
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
5
6
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
 
 
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
...
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
 
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
0
@@ -1,72 +1,76 @@
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
-# Thanks!
0
-# -- Marc
0
+# == God config file
0
+# http://god.rubyforge.org/
0
+# Author: Gump
0
+#
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
+# the following blog:
0
+# http://blog.alexgirard.com/2007/10/25/ruby-one-line-to-save-god/
0
+#
0
+require 'yaml'
0
 
0
-RAILS_ROOT = "/Users/marc/projects/refactormycode"
0
+config_path = "/etc/thin"
0
 
0
-God.watch do |w|
0
- w.name = "thin-3000"
0
- w.group = 'thins'
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
-
0
- # clean pid files before start if necessary
0
- w.behavior(:clean_pid_file)
0
-
0
- # determine the state on startup
0
- w.transition(:init, { true => :up, false => :start }) do |on|
0
- on.condition(:process_running) do |c|
0
- c.running = true
0
- end
0
- end
0
-
0
- # determine when process has finished starting
0
- w.transition([:start, :restart], :up) do |on|
0
- on.condition(:process_running) do |c|
0
- c.running = true
0
- end
0
-
0
- # failsafe
0
- on.condition(:tries) do |c|
0
- c.times = 5
0
- c.transition = :start
0
- end
0
- end
0
+Dir[config_path + "/*.yml"].each do |file|
0
+ config = YAML.load_file(file)
0
+ num_servers = config["servers"] ||= 1
0
 
0
- # start if process is not running
0
- w.transition(:up, :start) do |on|
0
- on.condition(:process_exits)
0
- end
0
-
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.interval = 20
0
- c.above = 50.megabytes
0
- c.times = [3, 5]
0
- end
0
-
0
- on.condition(:cpu_usage) do |c|
0
- c.interval = 10
0
- c.above = 10.percent
0
- c.times = [3, 5]
0
- end
0
- end
0
-
0
- # lifecycle
0
- w.lifecycle do |on|
0
- on.condition(:flapping) do |c|
0
- c.to_state = [:start, :restart]
0
- c.times = 5
0
- c.within = 5.minute
0
- c.transition = :unmonitored
0
- c.retry_in = 10.minutes
0
- c.retry_times = 5
0
- c.retry_within = 2.hours
0
+ for i in 0...num_servers
0
+ God.watch do |w|
0
+ w.group = "thin-" + File.basename(file, ".yml")
0
+ w.name = w.group + "-#{i}"
0
+
0
+ w.interval = 30.seconds
0
+
0
+ w.uid = config["user"]
0
+ w.gid = config["group"]
0
+
0
+ w.start = "thin start -C #{file} -o #{i}"
0
+ w.start_grace = 10.seconds
0
+
0
+ w.stop = "thin stop -C #{file} -o #{i}"
0
+ w.stop_grace = 10.seconds
0
+
0
+ w.restart = "thin restart -C #{file} -o #{i}"
0
+
0
+ pid_path = config["chdir"] + "/" + config["pid"]
0
+ ext = File.extname(pid_path)
0
+
0
+ w.pid_file = pid_path.gsub(/#{ext}$/, ".#{i}#{ext}")
0
+
0
+ w.behavior(:clean_pid_file)
0
+
0
+ w.start_if do |start|
0
+ start.condition(:process_running) do |c|
0
+ c.interval = 5.seconds
0
+ c.running = false
0
+ end
0
+ end
0
+
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
+ end
0
+
0
+ restart.condition(:cpu_usage) do |c|
0
+ c.above = 50.percent
0
+ c.times = 5
0
+ end
0
+ end
0
+
0
+ w.lifecycle do |on|
0
+ on.condition(:flapping) do |c|
0
+ c.to_state = [:start, :restart]
0
+ c.times = 5
0
+ c.within = 5.minutes
0
+ c.transition = :unmonitored
0
+ c.retry_in = 10.minutes
0
+ c.retry_times = 5
0
+ c.retry_within = 2.hours
0
+ end
0
+ end
0
     end
0
   end
0
 end

Comments

    No one has commented yet.