3 # Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
4 # Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. Neither the name of Apple Inc. ("Apple") nor the names of
16 # its contributors may be used to endorse or promote products derived
17 # from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # Script to run Apache with the same configuration as used in http layout tests.
40 use lib
$FindBin::Bin
;
45 my $allInterfaces = 0;
48 my $result = GetOptions
(
49 'all-interfaces|a' => \
$allInterfaces,
50 'help|h' => \
$showHelp,
51 'port=i' => \
$httpdPort,
54 if (!$result || @ARGV || $showHelp) {
55 print "Usage: " . basename
($0) . " [options]\n";
56 print " -a|--all-interfaces Bind to all interfaces\n";
57 print " -h|--help Show this help message\n";
58 print " -p|--port NNNN Bind to port NNNN\n";
63 my $productDir = productDir
();
68 if (-f
"/tmp/WebKit/httpd.pid") {
69 my $oldPid = `cat /tmp/WebKit/httpd.pid`;
71 if (0 != kill 0, $oldPid) {
72 print "\nhttpd is already running: pid $oldPid, killing...\n";
76 while ((0 != kill 0, $oldPid) && $retryCount) {
81 die "Timed out waiting for httpd to quit" unless $retryCount;
85 my $testDirectory = getcwd
() . "/LayoutTests";
86 my $httpdPath = "/usr/sbin/httpd";
87 $httpdPath = "/usr/sbin/apache2" if isDebianBased
();
88 my $httpdConfig = "$testDirectory/http/conf/httpd.conf";
89 $httpdConfig = "$testDirectory/http/conf/cygwin-httpd.conf" if isCygwin
();
90 $httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m
|Apache
/2|;
91 $httpdConfig = "$testDirectory/http/conf/apache2-debian-httpd.conf" if isDebianBased
();
92 my $documentRoot = "$testDirectory/http/tests";
93 my $typesConfig = "$testDirectory/http/conf/mime.types";
94 my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem";
96 my $listen = "127.0.0.1:$httpdPort";
97 $listen = "$httpdPort" if ($allInterfaces);
100 print "Starting httpd on port $httpdPort (all interfaces)...\n";
102 print "Starting httpd on <http://$listen/>...\n";
104 print "Press Ctrl+C to stop it.\n\n";
107 "-f", "$httpdConfig",
108 "-C", "DocumentRoot \"$documentRoot\"",
109 "-C", "Listen $listen",
110 "-c", "TypesConfig \"$typesConfig\"",
111 "-c", "CustomLog |/usr/bin/tee common",
112 "-c", "ErrorLog |/usr/bin/tee",
113 # Apache wouldn't run CGIs with permissions==700 otherwise.
114 "-c", "User \"#$<\"",
115 # Run in single-process mode, do not detach from the controlling terminal.
117 # Disable Keep-Alive support. Makes testing in multiple browsers easier (no need to wait
118 # for another browser's connection to expire).
122 # FIXME: Enable this on Windows once <rdar://problem/5345985> is fixed
123 push(@args, "-c", "SSLCertificateFile \"$sslCertificate\"") unless isCygwin
();
125 system($httpdPath, @args);
127 unlink "/tmp/WebKit/httpd.pid";