Skip to content

Commit d7d1c79

Browse files
committed
Merge branch 'webrick' of git://git.bogomips.org/git-svn
* 'webrick' of git://git.bogomips.org/git-svn: instaweb: add access+error logging for WEBrick instaweb: minimize moving parts for WEBrick instaweb: fix WEBrick server support
2 parents 730901a + e9323e7 commit d7d1c79

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

git-instaweb.sh

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ resolve_full_httpd () {
5757
httpd_only="${httpd%% *}" # cut on first space
5858
return
5959
;;
60+
*webrick*)
61+
# server is started by running via generated webrick.rb in
62+
# $fqgitdir/gitweb
63+
full_httpd="$fqgitdir/gitweb/webrick.rb"
64+
httpd_only="${httpd%% *}" # cut on first space
65+
return
66+
;;
6067
esac
6168

6269
httpd_only="$(echo $httpd | cut -f1 -d' ')"
@@ -188,40 +195,53 @@ GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl"
188195
export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
189196

190197
webrick_conf () {
198+
# webrick seems to have no way of passing arbitrary environment
199+
# variables to the underlying CGI executable, so we wrap the
200+
# actual gitweb.cgi using a shell script to force it
201+
wrapper="$fqgitdir/gitweb/$httpd/wrapper.sh"
202+
cat > "$wrapper" <<EOF
203+
#!/bin/sh
204+
# we use this shell script wrapper around the real gitweb.cgi since
205+
# there appears to be no other way to pass arbitrary environment variables
206+
# into the CGI process
207+
GIT_EXEC_PATH=$GIT_EXEC_PATH GIT_DIR=$GIT_DIR GITWEB_CONFIG=$GITWEB_CONFIG
208+
export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
209+
exec $root/gitweb.cgi
210+
EOF
211+
chmod +x "$wrapper"
212+
213+
# This assumes _ruby_ is in the user's $PATH. that's _one_
214+
# portable way to run ruby, which could be installed anywhere, really.
191215
# generate a standalone server script in $fqgitdir/gitweb.
192216
cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
217+
#!/usr/bin/env ruby
193218
require 'webrick'
194-
require 'yaml'
195-
options = YAML::load_file(ARGV[0])
196-
options[:StartCallback] = proc do
197-
File.open(options[:PidFile],"w") do |f|
198-
f.puts Process.pid
199-
end
200-
end
201-
options[:ServerType] = WEBrick::Daemon
219+
require 'logger'
220+
options = {
221+
:Port => $port,
222+
:DocumentRoot => "$root",
223+
:Logger => Logger.new('$fqgitdir/gitweb/error.log'),
224+
:AccessLog => [
225+
[ Logger.new('$fqgitdir/gitweb/access.log'),
226+
WEBrick::AccessLog::COMBINED_LOG_FORMAT ]
227+
],
228+
:DirectoryIndex => ["gitweb.cgi"],
229+
:CGIInterpreter => "$wrapper",
230+
:StartCallback => lambda do
231+
File.open("$fqgitdir/pid", "w") { |f| f.puts Process.pid }
232+
end,
233+
:ServerType => WEBrick::Daemon,
234+
}
235+
options[:BindAddress] = '127.0.0.1' if "$local" == "true"
202236
server = WEBrick::HTTPServer.new(options)
203237
['INT', 'TERM'].each do |signal|
204238
trap(signal) {server.shutdown}
205239
end
206240
server.start
207241
EOF
208-
# generate a shell script to invoke the above ruby script,
209-
# which assumes _ruby_ is in the user's $PATH. that's _one_
210-
# portable way to run ruby, which could be installed anywhere,
211-
# really.
212-
cat >"$fqgitdir/gitweb/$httpd" <<EOF
213-
#!/bin/sh
214-
exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
215-
EOF
216-
chmod +x "$fqgitdir/gitweb/$httpd"
217-
218-
cat >"$conf" <<EOF
219-
:Port: $port
220-
:DocumentRoot: "$root"
221-
:DirectoryIndex: ["gitweb.cgi"]
222-
:PidFile: "$fqgitdir/pid"
223-
EOF
224-
test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf"
242+
chmod +x "$fqgitdir/gitweb/$httpd.rb"
243+
# configuration is embedded in server script file, webrick.rb
244+
rm -f "$conf"
225245
}
226246

227247
lighttpd_conf () {

0 commit comments

Comments
 (0)