Changeset 18 for server/trunk/web/bin


Ignore:
Timestamp:
11/23/10 00:11:46 (14 years ago)
Author:
nanardon
Message:
  • improve database error management
  • add options to command line
File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/bin/sophie_scan

    r10 r18  
    77use Linux::Inotify2; 
    88use POSIX ":sys_wait_h"; 
     9use Getopt::Long; 
    910 
    10 $SIG{ALRM} = sub {}; 
     11GetOptions( 
     12    'bdelay=i' =>  \my $updated_inotify, 
     13    'd|daemon'  => \my $daemon, 
     14) or die "Wrong options"; 
     15 
    1116$SIG{CHLD} = sub { wait }; 
    1217 
    1318my %modified_paths; 
     19my $inotify = undef; 
     20$updated_inotify ||= 300; 
    1421 
     22if ($daemon) { 
     23    if (fork()) { 
     24        exit(0); 
     25    } 
     26} 
     27 
     28alarm($updated_inotify); 
    1529while (1) { 
    16     alarm 30; 
     30    local $SIG{ALRM} = sub { 
     31        $inotify = undef; 
     32        warn "reparse paths"; 
     33        alarm($updated_inotify); 
     34    }; 
    1735    if (update_base(keys %modified_paths)) { 
    1836        %modified_paths = (); 
    1937    } 
    20     my $inotify = inotify_path(); 
     38    $inotify ||= inotify_path(); 
    2139    $inotify->poll; 
    2240} 
     
    3553                warn $e->w->name; 
    3654                $modified_paths{$e->w->name} = 1; 
     55                1; 
    3756            } 
    3857        ) 
     
    5372    my @pkey; 
    5473    { 
    55         my $sophie = Sophie::Base->connect; 
     74        my $sophie = Sophie::Base->connect or do { 
     75            die "cannot read config file\n"; 
     76        }; 
    5677        @pkey = $sophie->resultset('Paths')->search( 
    5778            path => [ @path ], 
     
    100121        } 
    101122        1 while(waitpid(-1, 0) <= 0); 
     123        exit(0); 
    102124    } 
    103125    return 1; 
Note: See TracChangeset for help on using the changeset viewer.