@matheusbsbs / matheus-bagliano / commits / 425b78e886
Fork 0

instaweb: support for Ruby's WEBrick server

running the webrick server with git requires Ruby and Ruby's YAML and Webrick libraries (both of which come standard with Ruby). nice for single-user standalone invocations. the --httpd=webrick option generates a ruby script on the fly to read httpd.conf options and invoke the web server via library call. this script is placed in the .git/gitweb directory. it also generates a shell script in a feeble attempt to invoke ruby in a portable manner, which assumes that 'ruby' is in the user's $PATH. Signed-off-by: Mike Dalessio <mike@csa.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Mike Dalessio committed Oct 6, 2007 at 13:29 UTC 425b78e886e80f3c9f845edebfb199719a8f2d87
2 files changed +41 -1
Documentation/git-instaweb.txt
+1 -1
@@ -27,7 +27,7 @@ OPTIONS
27 The HTTP daemon command-line that will be executed.
28 Command-line options may be specified here, and the
29 configuration file will be added at the end of the command-line.
30 - Currently, lighttpd and apache2 are the only supported servers.
30 + Currently lighttpd, apache2 and webrick are supported.
31 (Default: lighttpd)
32
33 -m|--module-path::
git-instaweb.sh
+40
@@ -139,6 +139,43 @@ GIT_DIR="$fqgitdir"
139 export GIT_EXEC_PATH GIT_DIR
140
141
142 +webrick_conf () {
143 + # generate a standalone server script in $fqgitdir/gitweb.
144 + cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
145 +require 'webrick'
146 +require 'yaml'
147 +options = YAML::load_file(ARGV[0])
148 +options[:StartCallback] = proc do
149 + File.open(options[:PidFile],"w") do |f|
150 + f.puts Process.pid
151 + end
152 +end
153 +options[:ServerType] = WEBrick::Daemon
154 +server = WEBrick::HTTPServer.new(options)
155 +['INT', 'TERM'].each do |signal|
156 + trap(signal) {server.shutdown}
157 +end
158 +server.start
159 +EOF
160 + # generate a shell script to invoke the above ruby script,
161 + # which assumes _ruby_ is in the user's $PATH. that's _one_
162 + # portable way to run ruby, which could be installed anywhere,
163 + # really.
164 + cat >"$fqgitdir/gitweb/$httpd" <<EOF
165 +#!/bin/sh
166 +exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
167 +EOF
168 + chmod +x "$fqgitdir/gitweb/$httpd"
169 +
170 + cat >"$conf" <<EOF
171 +:Port: $port
172 +:DocumentRoot: "$fqgitdir/gitweb"
173 +:DirectoryIndex: ["gitweb.cgi"]
174 +:PidFile: "$fqgitdir/pid"
175 +EOF
176 + test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf"
177 +}
178 +
179 lighttpd_conf () {
180 cat > "$conf" <<EOF
181 server.document-root = "$fqgitdir/gitweb"
@@ -239,6 +276,9 @@ case "$httpd" in
276 *apache2*)
277 apache2_conf
278 ;;
279 +webrick)
280 + webrick_conf
281 + ;;
282 *)
283 echo "Unknown httpd specified: $httpd"
284 exit 1