2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebKitTools / Scripts / run-webkit-httpd
bloba64eef657f23111935e046819f9437e3c0260537
1 #!/usr/bin/perl
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
8 # are met:
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.
32 use strict;
33 use warnings;
35 use Cwd;
36 use File::Basename;
37 use Getopt::Long;
38 use FindBin;
40 use lib $FindBin::Bin;
41 use webkitdirs;
43 # Argument handling
44 my $httpdPort = 8000;
45 my $allInterfaces = 0;
46 my $showHelp;
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";
59 exit 1;
62 setConfiguration();
63 my $productDir = productDir();
64 chdirWebKit();
66 mkdir "/tmp/WebKit";
68 if (-f "/tmp/WebKit/httpd.pid") {
69 my $oldPid = `cat /tmp/WebKit/httpd.pid`;
70 chomp $oldPid;
71 if (0 != kill 0, $oldPid) {
72 print "\nhttpd is already running: pid $oldPid, killing...\n";
73 kill 15, $oldPid;
75 my $retryCount = 20;
76 while ((0 != kill 0, $oldPid) && $retryCount) {
77 sleep 1;
78 --$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);
99 if ($allInterfaces) {
100 print "Starting httpd on port $httpdPort (all interfaces)...\n";
101 } else {
102 print "Starting httpd on <http://$listen/>...\n";
104 print "Press Ctrl+C to stop it.\n\n";
106 my @args = (
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.
116 "-X",
117 # Disable Keep-Alive support. Makes testing in multiple browsers easier (no need to wait
118 # for another browser's connection to expire).
119 "-c", "KeepAlive 0"
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";