instaweb: minimize moving parts for WEBrick
Since there are WEBrick configuration settings (including the upcoming AccessLog support) that cannot be represented in YAML and require Ruby anyways, the YAML config file is an unnecessary layer of complexity. Additionally, the shell script wrapper to start WEBrick is unecessary since our generated Ruby script can be made executable in the same manner with /usr/bin/env. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Aug 5, 2010 at 08:35 UTC
f46e130439a57ce44708971183adab7e58512b34
1 file changed
+17
-28
git-instaweb.sh
+17
-28
@@ -58,9 +58,9 @@ resolve_full_httpd () {
58
return
59
;;
60
*webrick*)
61
- # server is started by running via generated webrick.sh in
61
+ # server is started by running via generated webrick.rb in
62
# $fqgitdir/gitweb
63
- full_httpd="$fqgitdir/gitweb/webrick.sh"
63
+ full_httpd="$fqgitdir/gitweb/webrick.rb"
64
httpd_only="${httpd%% *}" # cut on first space
65
return
66
;;
@@ -214,39 +214,28 @@ EOF
214
# portable way to run ruby, which could be installed anywhere, really.
215
# generate a standalone server script in $fqgitdir/gitweb.
216
cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
217
+#!/usr/bin/env ruby
218
require 'webrick'
218
-require 'yaml'
219
-options = YAML::load_file(ARGV[0])
220
-options[:StartCallback] = proc do
221
- File.open(options[:PidFile],"w") do |f|
222
- f.puts Process.pid
223
- end
224
-end
225
-options[:ServerType] = WEBrick::Daemon
219
+options = {
220
+ :Port => $port,
221
+ :DocumentRoot => "$root",
222
+ :DirectoryIndex => ["gitweb.cgi"],
223
+ :CGIInterpreter => "$wrapper",
224
+ :StartCallback => lambda do
225
+ File.open("$fqgitdir/pid", "w") { |f| f.puts Process.pid }
226
+ end,
227
+ :ServerType => WEBrick::Daemon,
228
+}
229
+options[:BindAddress] = '127.0.0.1' if "$local" == "true"
230
server = WEBrick::HTTPServer.new(options)
231
['INT', 'TERM'].each do |signal|
232
trap(signal) {server.shutdown}
233
end
234
server.start
235
EOF
232
- # generate a shell script to invoke the above ruby script,
233
- # which assumes _ruby_ is in the user's $PATH. that's _one_
234
- # portable way to run ruby, which could be installed anywhere,
235
- # really.
236
- cat >"$fqgitdir/gitweb/$httpd.sh" <<EOF
237
-#!/bin/sh
238
-exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
239
-EOF
240
- chmod +x "$fqgitdir/gitweb/$httpd.sh"
241
-
242
- cat >"$conf" <<EOF
243
-:Port: $port
244
-:DocumentRoot: "$root"
245
-:DirectoryIndex: ["gitweb.cgi"]
246
-:PidFile: "$fqgitdir/pid"
247
-:CGIInterpreter: "$wrapper"
248
-EOF
249
- test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf"
236
+ chmod +x "$fqgitdir/gitweb/$httpd.rb"
237
+ # configuration is embedded in server script file, webrick.rb
238
+ rm -f "$conf"
239
}
240
241
lighttpd_conf () {