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 --config option to load options from a config file in thin script 
[Matt Todd].
macournoyer (author)
Mon Jan 21 20:30:00 -0800 2008
commit  ff260c2dd071d7568068905905603e2c850ae402
tree    1e082acb3534d8b4863058033484d3503264c78a
parent  42dea94c69a651d7666ce1f7114c356d8099a27e
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 == 0.5.5 Pony release
0
+ * Add --config option to load options from a config file in thin script [Matt Todd].
0
  * Alter response headers to output directly to a string.
0
  * Improve specs stability.
0
  * Move request body to a Tempfile if too big (> 112 MB)
...
3
4
5
 
6
7
 
8
9
10
...
44
45
46
 
47
48
49
50
51
52
...
51
52
53
54
55
56
57
58
59
 
60
61
62
63
64
 
 
 
 
 
 
 
 
 
 
65
 
 
66
67
68
...
87
88
89
 
 
90
91
92
...
95
96
97
 
 
98
99
100
101
102
103
...
106
107
108
 
 
109
 
 
 
 
 
 
 
 
110
111
112
 
113
 
 
114
115
116
...
3
4
5
6
7
 
8
9
10
11
...
45
46
47
48
49
50
51
52
53
54
...
53
54
55
 
 
56
57
58
 
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
99
100
101
102
103
104
105
106
...
109
110
111
112
113
114
115
116
117
118
119
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
 
138
139
140
141
142
143
144
0
@@ -3,8 +3,9 @@
0
 # Run <tt>thin -h</tt> to get more usage.
0
 require File.dirname(__FILE__) + '/../lib/thin'
0
 require 'optparse'
0
+require 'yaml'
0
 
0
-COMMANDS = %w(start stop restart)
0
+COMMANDS = %w(start stop restart config)
0
 
0
 # Default options values
0
 options = {
0
@@ -44,6 +45,7 @@
0
   opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| options[:user] = user }
0
   opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| options[:group] = group }
0
   opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| options[:prefix] = path }
0
+ opts.on("-C", "--config PATH", "Load option from a config file") { |file| options[:config] = file }
0
   
0
   opts.separator ""
0
   opts.separator "Common options:"
0
0
0
0
@@ -51,18 +53,28 @@
0
   opts.on_tail("-D", "--debug", "Set debbuging on") { $DEBUG = true }
0
   opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
0
   opts.on_tail('-v', '--version', "Show version") { puts Thin::SERVER; exit }
0
-
0
- opts.parse! ARGV
0
 end
0
 
0
 
0
-# == Commands definitions
0
+# == Utilities
0
 
0
 def cluster?(options)
0
   options[:servers] && options[:servers] > 1
0
 end
0
 
0
+def load_options_from_config_file!(options)
0
+ file = options.delete(:config)
0
+ YAML.load_file(file).each do |key, value|
0
+ options[key.to_sym] = value
0
+ end
0
+end
0
+
0
+
0
+# == Commands definitions
0
+
0
 def start(options)
0
+ load_options_from_config_file! options
0
+
0
   if cluster?(options)
0
     Thin::Cluster.new(options).start
0
   else
0
@@ -87,6 +99,8 @@
0
 end
0
 
0
 def stop(options)
0
+ load_options_from_config_file! options
0
+
0
   if cluster?(options)
0
     Thin::Cluster.new(options).stop
0
   else
0
@@ -95,6 +109,8 @@
0
 end
0
 
0
 def restart(options)
0
+ load_options_from_config_file! options
0
+
0
   if cluster?(options)
0
     Thin::Cluster.new(options).restart
0
   else
0
0
0
0
@@ -106,11 +122,23 @@
0
   end
0
 end
0
 
0
+def config(options)
0
+ config_file = options.delete(:config)
0
 
0
+ # Stringify keys
0
+ options.keys.each { |o| options[o.to_s] = options.delete(o) }
0
+
0
+ File.open(config_file, 'w') { |f| f << options.to_yaml }
0
+ puts "Wrote configuration to #{config_file}"
0
+end
0
+
0
+
0
 # == Runs the command
0
 
0
-Dir.chdir(options[:chdir])
0
+opts.parse! ARGV
0
 command = ARGV[0]
0
+
0
+Dir.chdir(options[:chdir])
0
 
0
 if COMMANDS.include?(command)
0
   send(command, options)

Comments

    No one has commented yet.