Changeset 3886 for trunk/tools

Show
Ignore:
Timestamp:
06/19/09 04:11:07 (5 months ago)
Author:
fumiakiy
Message:

Merged fringale down to trunk. "svn merge -r 3460:3877 http://code.sixapart.com/svn/movabletype/branches/fringale ."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tools/run-periodic-tasks

    r3531 r3886  
    99use strict; 
    1010 
    11 use lib 'lib', '../lib'; 
     11use lib 'lib', '../lib', 'extlib', '../extlib'; 
    1212 
    1313my $daemonize = 0; 
     
    1818my $scoreboard; 
    1919my $randomize_jobs = 0; 
    20 my $trace_objects = 0; 
     20my $trace_objects  = 0; 
    2121 
    2222require Getopt::Long; 
     
    3030    "leak"         => \$trace_objects, 
    3131); 
     32require MT::TheSchwartz; 
    3233 
    33 if ( $trace_objects ) { 
     34if ($trace_objects) { 
    3435    require Devel::Leak::Object; 
    35     Devel::Leak::Object->import( qw{ GLOBAL_bless } ); 
     36    Devel::Leak::Object->import(qw{ GLOBAL_bless }); 
    3637} 
    3738 
     39my $proc_process_table = eval { 
     40    require Proc::ProcessTable; 
     41    1; 
     42}; 
     43 
     44$@ = undef; 
     45 
    3846my %cfg; 
    39 $cfg{verbose} = $verbose; 
     47$cfg{verbose}    = $verbose; 
    4048$cfg{scoreboard} = $scoreboard; 
    4149$cfg{prioritize} = 1; 
    42 $cfg{randomize} = $randomize_jobs; 
     50$cfg{randomize}  = $randomize_jobs; 
    4351 
    4452require MT::Bootstrap; 
     
    4654 
    4755my $mt = MT->new() or die MT->errstr; 
     56if ( defined(MT->config('RPTProcessCap')) && $proc_process_table ) { 
     57    my $t = new Proc::ProcessTable; 
     58    my $rpt_count; 
     59    foreach my $p ( @{ $t->table } ) { 
     60        my $cmd = $p->cmndline; 
     61        if ( $cmd =~ /^perl/ && $cmd =~ /run-periodic-tasks/ ) { 
     62            $rpt_count += 1; 
     63        } 
     64    } 
     65    if ( $rpt_count > MT->config('RPTProcessCap') ) { 
     66        $rpt_count = $rpt_count - 1;    # Don't report this RPT 
     67        die "$rpt_count processes already running; cancelling RPT launch\n"; 
     68    } 
     69} 
    4870 
    49 $mt->{vtbl} = { }; 
    50 $mt->{is_admin} = 0; 
    51 $mt->{template_dir} = 'cms'; 
    52 $mt->{user_class} = 'MT::Author'; 
     71if ( MT->config('RPTFreeMemoryLimit') ) { 
     72    my $limit = MT->config('RPTFreeMemoryLimit'); 
     73    if ( $limit and ! MT::TheSchwartz::_has_enough_swap($limit) ) { 
     74        die 
     75            "Free memory below RPT limit; cancelling RPT launch\n"; 
     76    } 
     77} 
     78if ( MT->config('RPTFreeSwapLimit') ) { 
     79    my $swaplimit = MT->config('RPTSwapMemoryLimit'); 
     80    if ( $swaplimit and ! MT::TheSchwartz::_has_enough_swap($swaplimit) ) { 
     81        die 
     82            "Free swap memory below RPT limit; cancelling RPT launch\n"; 
     83    } 
     84} 
     85 
     86$mt->{vtbl}                 = {}; 
     87$mt->{is_admin}             = 0; 
     88$mt->{template_dir}         = 'cms'; 
     89$mt->{user_class}           = 'MT::Author'; 
    5390$mt->{plugin_template_path} = 'tmpl'; 
    54 $mt->run_callbacks('init_app', $mt); 
     91$mt->run_callbacks( 'init_app', $mt ); 
    5592 
    5693my $client = eval { 
     
    6198    $c; 
    6299}; 
    63 if ((my $error = $@) && $verbose) { 
     100if ( ( my $error = $@ ) && $verbose ) { 
    64101    print STDERR "Error initializing TheSchwartz: $error\n"; 
    65102} 
    66103 
    67 if ($daemonize && $client) { 
     104if ( $daemonize && $client ) { 
    68105    $client->work_periodically($sleep); 
    69 } else { 
     106} 
     107else { 
     108 
    70109    # First, run periodic tasks 
    71110    $mt->run_tasks();