Changeset 435


Ignore:
Timestamp:
06/25/12 17:39:09 (12 years ago)
Author:
nanardon
Message:
  • add iniscript for sophie-update
  • sophie-update update also maintainers
Location:
server/trunk/web
Files:
2 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • server/trunk/web/Makefile.PL

    r377 r435  
    4343 
    4444install_script glob('script/*.pl'); 
    45 install_script qw(bin/sophie_fetch_maint bin/sophie_rescan bin/sophie_scan); 
     45install_script qw(bin/sophie_fetch_maint bin/sophie_rescan bin/sophie-update); 
    4646 
    4747WriteMakefile( 
  • server/trunk/web/Sophie.spec.in

    r383 r435  
    8383install -m 755 bin/sophie_cron %buildroot/%_sysconfdir/cron.daily/sophie_cron 
    8484 
     85mkdir -p %buildroot/%_sysconfdir/init.d 
     86 
     87install -m 755 sysinit/sophie-scan %buildroot/%_sysconfdir/init.d/sophie-scan 
     88 
    8589%clean 
    8690rm -rf %buildroot 
     
    9195%dir %_sysconfdir/sophie 
    9296%_sysconfdir/cron.daily/sophie_cron 
     97%_sysconfdir/init.d/sophie-scan 
    9398%config(noreplace) %_sysconfdir/sophie/* 
    9499%_bindir/* 
  • server/trunk/web/bin/sophie-update

    r434 r435  
    55use Getopt::Long; 
    66use Sophie::Scan; 
     7use Sophie::Base; 
    78use Sys::Syslog; 
    89use Pod::Usage; 
     
    1819require Sophie::Scan::RpmsPath; 
    1920 
    20 sub process { 
     21sub process_rpms { 
    2122    my $scan = Sophie::Scan->new; 
    2223    $scan->update_meta_paths; 
     
    5455} 
    5556 
    56 openlog('sophie-notify', 'ndelay,pid' . ($daemon ? '' : ',perror'), 'user'); 
     57sub process_maint { 
     58    my $sophie = Sophie::Base->connect; 
     59 
     60    foreach my $maintsource ( 
     61        $sophie->resultset('MaintSources') 
     62        ->search->all) { 
     63 
     64        my $realclass = 'Sophie::Maint::' . $maintsource->accessor; 
     65        no strict qw(refs); 
     66        eval "require $realclass;"; 
     67        next if($@); 
     68 
     69        warn "Updating maintainers for " . $maintsource->label . "\n"; 
     70        my $fetcher = $realclass->new($maintsource); 
     71        if (my $list = $fetcher->fetch) { 
     72            $sophie->resultset('MaintRpm')->search( 
     73                { 
     74                    sources => $maintsource->pkey, 
     75                } 
     76            )->delete; 
     77 
     78            foreach (@$list) { 
     79                $_->{sources} = $maintsource->pkey; 
     80            } 
     81 
     82            $sophie->txn_do( 
     83                sub { 
     84                    $sophie->resultset('MaintRpm')->populate($list) && 
     85                    $maintsource->update({ lastupdated => 'now()' }); 
     86                } 
     87            ); 
     88        } 
     89    } 
     90} 
     91 
     92openlog('sophie-update', 'ndelay,pid' . ($daemon ? '' : ',perror'), 'user'); 
    5793$SIG{__WARN__} = sub { 
    5894    syslog('warning', @_); 
     
    93129$sleep ||= 60; 
    94130 
     131my $lastmaint = 0; 
     132 
    95133while (1) { 
    96134    my $csleep = int(rand($sleep) + ($sleep / 2 )); 
     
    99137        waitpid($pid, 0); 
    100138    } else { 
    101         process(); 
     139        process_rpms(); 
    102140        exit(0); 
    103141    } 
     142 
     143    if ($lastmaint < time - ($sleep * 100)) { 
     144        if (my $pid = fork) { 
     145            waitpid($pid, 0); 
     146            $lastmaint = time; 
     147        } else { 
     148            process_maint(); 
     149            exit(0); 
     150        } 
     151    } 
     152     
    104153    my $delay = $csleep - (time - $currenttime); 
    105154 
Note: See TracChangeset for help on using the changeset viewer.