From 422bff280297b55aff6542cc5df1c078f37ab673 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 Aug 2010 09:51:25 +0000 Subject: [PATCH 1/3] instaweb: fix WEBrick server support This has been broken since commit be5347b ("httpd logs in a "$httpd_only" subdirectory"). Since WEBrick has no other way of preserving environment variables needed for gitweb, we create a shell script wrapper that sets the environment variables as our CGI interpreter to run gitweb.cgi. Signed-off-by: Eric Wong --- git-instaweb.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/git-instaweb.sh b/git-instaweb.sh index b7342e22c8..5d4ddc8f58 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -57,6 +57,13 @@ resolve_full_httpd () { httpd_only="${httpd%% *}" # cut on first space return ;; + *webrick*) + # server is started by running via generated webrick.sh in + # $fqgitdir/gitweb + full_httpd="$fqgitdir/gitweb/webrick.sh" + httpd_only="${httpd%% *}" # cut on first space + return + ;; esac httpd_only="$(echo $httpd | cut -f1 -d' ')" @@ -188,6 +195,23 @@ GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl" export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG webrick_conf () { + # webrick seems to have no way of passing arbitrary environment + # variables to the underlying CGI executable, so we wrap the + # actual gitweb.cgi using a shell script to force it + wrapper="$fqgitdir/gitweb/$httpd/wrapper.sh" + cat > "$wrapper" <"$fqgitdir/gitweb/$httpd.rb" <"$fqgitdir/gitweb/$httpd" <"$fqgitdir/gitweb/$httpd.sh" <"$conf" <> "$conf" } From f46e130439a57ce44708971183adab7e58512b34 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 5 Aug 2010 08:35:45 +0000 Subject: [PATCH 2/3] 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 --- git-instaweb.sh | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/git-instaweb.sh b/git-instaweb.sh index 5d4ddc8f58..e69fb74fef 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -58,9 +58,9 @@ resolve_full_httpd () { return ;; *webrick*) - # server is started by running via generated webrick.sh in + # server is started by running via generated webrick.rb in # $fqgitdir/gitweb - full_httpd="$fqgitdir/gitweb/webrick.sh" + full_httpd="$fqgitdir/gitweb/webrick.rb" httpd_only="${httpd%% *}" # cut on first space return ;; @@ -214,39 +214,28 @@ EOF # portable way to run ruby, which could be installed anywhere, really. # generate a standalone server script in $fqgitdir/gitweb. cat >"$fqgitdir/gitweb/$httpd.rb" < $port, + :DocumentRoot => "$root", + :DirectoryIndex => ["gitweb.cgi"], + :CGIInterpreter => "$wrapper", + :StartCallback => lambda do + File.open("$fqgitdir/pid", "w") { |f| f.puts Process.pid } + end, + :ServerType => WEBrick::Daemon, +} +options[:BindAddress] = '127.0.0.1' if "$local" == "true" server = WEBrick::HTTPServer.new(options) ['INT', 'TERM'].each do |signal| trap(signal) {server.shutdown} end server.start EOF - # generate a shell script to invoke the above ruby script, - # which assumes _ruby_ is in the user's $PATH. that's _one_ - # portable way to run ruby, which could be installed anywhere, - # really. - cat >"$fqgitdir/gitweb/$httpd.sh" <"$conf" <> "$conf" + chmod +x "$fqgitdir/gitweb/$httpd.rb" + # configuration is embedded in server script file, webrick.rb + rm -f "$conf" } lighttpd_conf () { From e9323e7f09d171739e8dbc9d60d77281caa06177 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 5 Aug 2010 08:46:04 +0000 Subject: [PATCH 3/3] instaweb: add access+error logging for WEBrick This allows WEBrick to support all the logging functionality in a manner consistent with the other web servers. Signed-off-by: Eric Wong --- git-instaweb.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/git-instaweb.sh b/git-instaweb.sh index e69fb74fef..e6f6ecda17 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -216,9 +216,15 @@ EOF cat >"$fqgitdir/gitweb/$httpd.rb" < $port, :DocumentRoot => "$root", + :Logger => Logger.new('$fqgitdir/gitweb/error.log'), + :AccessLog => [ + [ Logger.new('$fqgitdir/gitweb/access.log'), + WEBrick::AccessLog::COMBINED_LOG_FORMAT ] + ], :DirectoryIndex => ["gitweb.cgi"], :CGIInterpreter => "$wrapper", :StartCallback => lambda do