Changeset 912

Show
Ignore:
Timestamp:
04/25/07 18:48:23 (3 years ago)
Author:
bradfitz
Message:

lighttpd support

Location:
trunk/server
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/server/CHANGES

    r910 r912  
     1        * lighttpd support 
     2 
    13        * abstract out the HTTP server support in mogstored, so 
    24          mogstored isn't just a perlbal wrapper, but an anything 
  • trunk/server/lib/Mogstored/HTTPServer.pm

    r910 r912  
    77    $self->{listen}   = delete $opts{listen}; 
    88    $self->{maxconns} = delete $opts{maxconns}; 
     9    $self->{bin}      = delete $opts{bin}; 
    910    die "unknown opts" if %opts; 
    1011    return $self; 
     
    2425} 
    2526 
     27sub listen_port { 
     28    my $self = shift; 
     29    my $port = $self->{listen}; 
     30    $port =~ s/^.+://; 
     31    die "not numeric port?" unless $port =~ /^\d+$/; 
     32    return $port; 
     33} 
    2634 
    27351; 
  • trunk/server/lib/Mogstored/HTTPServer/Lighttpd.pm

    r910 r912  
    22use strict; 
    33use base 'Mogstored::HTTPServer'; 
     4use File::Temp (); 
    45 
    56sub start { 
    6     die "TODO: start lighttpd"; 
     7    my $self = shift; 
     8    my $exe = $self->{bin}; 
     9 
     10    if ($exe && -x $exe) { 
     11        die "Provided lighttpd path $exe not valid.\n"; 
     12    } 
     13    unless ($exe) { 
     14        my @loc = qw(/usr/local/sbin/lighttpd 
     15                     /usr/sbin/lighttpd 
     16                     /usr/local/bin/lighttpd 
     17                     /usr/bin/lighttpd 
     18                     ); 
     19        foreach my $loc (@loc) { 
     20            $exe = $loc; 
     21            last if -x $exe; 
     22        } 
     23        unless (-x $exe) { 
     24            die "Can't find lighttpd in @loc\n"; 
     25        } 
     26    } 
     27 
     28    my $pid = fork(); 
     29    die "Can't fork: $!" unless defined $pid; 
     30 
     31    if ($pid) { 
     32        $self->{pid} = $pid; 
     33        Mogstored->on_pid_death($pid => sub { 
     34            die "lighttpd died"; 
     35        }); 
     36        return; 
     37    } 
     38 
     39    my ($fh, $filename) = File::Temp::tempfile(); 
     40    $self->{temp_conf_file} = $filename; 
     41    my $portnum = $self->listen_port; 
     42 
     43    print $fh qq{ 
     44server.document-root = "$self->{docroot}" 
     45server.port = $portnum 
     46server.modules = ( "mod_webdav" ) 
     47webdav.activate = "enable" 
     48}; 
     49 
     50    exec $exe, "-D", "-f", $filename; 
     51} 
     52 
     53sub DESTROY { 
     54    my $self = shift; 
     55    unlink $self->{temp_conf_file} if $self->{temp_conf_file}; 
    756} 
    857 
  • trunk/server/mogstored

    r911 r912  
    1515use IO::Socket::INET; 
    1616use POSIX qw(WNOHANG); 
    17 use Fcntl qw(SEEK_CUR SEEK_SET SEEK_END O_RDWR O_CREAT O_TRUNC); 
    1817use Perlbal 1.52; 
    1918use FindBin qw($Bin $RealScript); 
     
    4544my $default_config = "/etc/mogilefs/mogstored.conf"; 
    4645my $server      = "perlbal"; 
     46my $serverbin   = ""; 
    4747 
    4848my %config_opts = ( 
     
    5555                   'maxconns=i'   => \$max_conns, 
    5656                   'server=s'     => \$server, 
     57                   'serverbin=s'  => \$serverbin, 
    5758                   ); 
    5859usage() unless Getopt::Long::GetOptions(%config_opts); 
     
    7879# start HTTP server 
    7980my $httpsrv_class = "Mogstored::HTTPServer::" . ucfirst($server); 
    80 my $httpsrv       = $httpsrv_class->new(listen   => $http_listen, 
     81my $httpsrv       = $httpsrv_class->new( 
     82                                        listen   => $http_listen, 
    8183                                        docroot  => $docroot, 
    82                                         maxconns => $max_conns); 
     84                                        maxconns => $max_conns, 
     85                                        bin      => $serverbin, 
     86                                        ); 
    8387$httpsrv->start; 
    8488 
     
    169173} 
    170174 
     175sub Mogstored::on_pid_death { 
     176    my ($class, $pid, $code) = @_; 
     177    $on_death{$pid} = $code; 
     178} 
     179 
    171180# returns $pid of child, if parent, else runs child. 
    172181sub start_disk_usage_process {