Skip to content

Commit 425b78e

Browse files
flavorjonesspearce
authored andcommitted
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>
1 parent 14b45b6 commit 425b78e

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Documentation/git-instaweb.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OPTIONS
2727
The HTTP daemon command-line that will be executed.
2828
Command-line options may be specified here, and the
2929
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.
3131
(Default: lighttpd)
3232

3333
-m|--module-path::

git-instaweb.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,43 @@ GIT_DIR="$fqgitdir"
139139
export GIT_EXEC_PATH GIT_DIR
140140

141141

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+
142179
lighttpd_conf () {
143180
cat > "$conf" <<EOF
144181
server.document-root = "$fqgitdir/gitweb"
@@ -239,6 +276,9 @@ case "$httpd" in
239276
*apache2*)
240277
apache2_conf
241278
;;
279+
webrick)
280+
webrick_conf
281+
;;
242282
*)
243283
echo "Unknown httpd specified: $httpd"
244284
exit 1

0 commit comments

Comments
 (0)