Changeset 434
- Timestamp:
- 06/25/12 16:55:47 (12 years ago)
- Location:
- server/trunk/web
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
server/trunk/web/bin/sophie_scan
r420 r434 5 5 use Getopt::Long; 6 6 use Sophie::Scan; 7 use Sys::Syslog; 8 use Pod::Usage; 9 10 GetOptions( 11 'd' => \my $daemon, 12 'sleep=i' => \my $sleep, 13 'runas=s' => \my $runas, 14 'pidfile=s' => \my $pidfile, 15 ) or do { pod2usage(1) }; 7 16 8 17 $ENV{LC_ALL} = 'C'; 9 18 require Sophie::Scan::RpmsPath; 10 19 11 my $scan = Sophie::Scan->new; 12 $scan->update_meta_paths; 20 sub process { 21 my $scan = Sophie::Scan->new; 22 $scan->update_meta_paths; 13 23 14 my @pkey = $scan->list_unscanned_paths;24 my @pkey = $scan->list_unscanned_paths; 15 25 16 foreach my $pathkey (@pkey) {17 18 my $time = time;19 my $mark = 0;20 my @delta;26 foreach my $pathkey (@pkey) { 27 28 my $time = time; 29 my $mark = 0; 30 my @delta; 21 31 22 { 23 my $path = Sophie::Scan::RpmsPath 24 ->new($pathkey, Sophie::Scan->new); 25 #$path->set_no_needupdate; 32 { 33 my $path = Sophie::Scan::RpmsPath 34 ->new($pathkey, Sophie::Scan->new); 26 35 27 $mark = $path->get_needupdate;28 @delta = $path->find_delta;29 }36 $mark = $path->get_needupdate; 37 @delta = $path->find_delta; 38 } 30 39 31 while (my @d = splice(@delta, 0, 10)) {32 my $scan = Sophie::Scan->new;33 my $path = Sophie::Scan::RpmsPath->new($pathkey, $scan);34 $path->update_content(@d);35 last if (time > $time + 7 * 60);36 }40 while (my @d = splice(@delta, 0, 10)) { 41 my $scan = Sophie::Scan->new; 42 my $path = Sophie::Scan::RpmsPath->new($pathkey, $scan); 43 $path->update_content(@d); 44 last if (time > $time + 7 * 60); 45 } 37 46 38 if (!@delta) { # update only if we finished 39 my $path = Sophie::Scan::RpmsPath->new($pathkey, Sophie::Scan->new); 40 $path->set_updated; 41 $path->set_no_needupdate 42 unless ($mark ne $path->get_needupdate); 47 if (!@delta) { # update only if we finished 48 my $path = Sophie::Scan::RpmsPath->new($pathkey, Sophie::Scan->new); 49 $path->set_updated; 50 $path->set_no_needupdate 51 unless ($mark ne $path->get_needupdate); 52 } 43 53 } 44 54 } 45 55 56 openlog('sophie-notify', 'ndelay,pid' . ($daemon ? '' : ',perror'), 'user'); 57 $SIG{__WARN__} = sub { 58 syslog('warning', @_); 59 }; 60 $SIG{__DIE__} = sub { 61 syslog('crit', @_); 62 exit(1); 63 }; 64 65 if ($daemon) { 66 if (fork()) { 67 exit(0); 68 } 69 warn "Fork done, entering daemon mode\n"; 70 } 71 72 if ($pidfile) { 73 if (open(my $handle, '>', $pidfile)) { 74 print $handle $$ . "\n"; 75 close($handle); 76 } else { 77 die "Can't write pidfile $pidfile, exiting :\\\n"; 78 } 79 } 80 81 82 if ($runas) { 83 my ($login,$pass,$uid,$gid) = $runas =~ /^\d/ 84 ? getpwuid($runas) 85 : getpwnam($runas); 86 87 $> = $uid; $) = $gid; 88 if ($> ne $uid) { 89 die "Cannot change to user $runas\n"; 90 } 91 } 92 93 $sleep ||= 60; 94 95 while (1) { 96 my $csleep = int(rand($sleep) + ($sleep / 2 )); 97 my $currenttime = time; 98 if (my $pid = fork) { 99 waitpid($pid, 0); 100 } else { 101 process(); 102 exit(0); 103 } 104 my $delay = $csleep - (time - $currenttime); 105 106 if ($delay > 0) { 107 warn "sleep $delay\n"; 108 sleep $delay; 109 } 110 } -
server/trunk/web/lib/Sophie/Controller/Admin.pm
r375 r434 455 455 } 456 456 457 sub help : private { 458 my ( $self, $c, $cmd ) = @_; 459 my $ctx = $c->session->{admin_ctx} || ''; 460 my $module = 'Admin::Cli' . ($ctx ? "::$ctx" : ''); 461 if ($cmd) { 462 my @message = grep { /\S+/ } split(/\n/, 463 $c->model('Help::POD')->admin_help_text($ctx, $cmd) || 'No help available'); 464 return $c->stash->{xmlrpc} = [ $self->prompt($c), \@message ]; 465 } else { 466 return $c->stash->{xmlrpc} = [ 467 $self->prompt($c), 468 [ 469 'available command:', 470 join(', ', sort grep { $_ !~ /^end$/ } 471 ('help', @{ $c->controller($module)->_commands })), 472 ] 473 ]; 474 } 475 } 476 477 sub prompt : XMLRPC { 478 my ($self, $c) = @_; 479 my $ctx = $c->session->{admin_ctx} || ''; 480 my $path = '/admin/cli' . ($ctx ? lc("/$ctx") : ''); 481 if ($c->get_action( 'prompt', $path )) { 482 return $c->stash->{xmlrpc} = $c->forward("$path/prompt"); 483 } else { 484 return $c->stash->{xmlrpc} = '> '; 485 } 486 } 487 488 sub cli : XMLRPC { 489 my ($self, $c, $cmd, @args) = @_; 490 491 if ($cmd eq 'help') { 492 $c->go('help', [ @args ]); 493 } 494 495 my $ctx = $c->session->{admin_ctx} || ''; 496 my $path = '/admin/cli' . ($ctx ? lc("/$ctx") : ''); 497 if ($c->get_action( $cmd, $path )) { 498 return $c->go($path . '/' . $cmd, [ @args ]); 499 } else { 500 $c->error( "No such command $cmd" ); 501 } 502 } 503 504 sub complete : XMLRPC { 505 my ($self, $c, $cmd, @args) = @_; 506 507 my $ctx = $c->session->{admin_ctx} || ''; 508 my $path = '/admin/cli' . ($ctx ? lc("/$ctx") : ''); 509 if ($c->get_action( "_c_$cmd", $path )) { 510 my $vals = $c->go($path . '/' . "_c_$cmd", [ @args ]); 511 return $args[-1] ? [ grep { index($_, $args[-1]) == 0 } @$vals ] : $vals; 512 } else { 513 return $c->stash->{xmlrpc} = []; 514 } 515 } 516 517 457 518 =head1 AUTHOR 458 519 -
server/trunk/web/lib/Sophie/Model/Help/POD.pm
r260 r434 76 76 } 77 77 78 sub admin_help_text { 79 my ($self, $context, $cmd) = @_; 80 my $module = 'Admin::Cli' . ($context ? "::$context" : ''); 81 my $botpom = $self->{pom}{$module}; 82 foreach my $head1 ($botpom->content) { 83 $head1->title eq 'AVAILABLE FUNCTIONS' or next; 84 foreach ($head1->content) { 85 $_->title =~ /^\Q$cmd\E( |$)/ or next; 86 my $ppvt = Pod::POM::View::Text->new; 87 return $_->present($ppvt); 88 } 89 last; 90 } 91 return; 92 } 93 78 94 sub chat_functions { 79 95 my ($self) = @_; -
server/trunk/web/lib/Sophie/Scan/RpmsPath.pm
r419 r434 65 65 my ($self) = @_; 66 66 67 warn " $$ " . $self->path;67 warn "Scanning " . $self->path . "\n"; 68 68 69 69 my @delta; … … 152 152 sub remove_rpm { 153 153 my ($self, $rpm) = @_; 154 warn " $$ deleting $rpm";154 warn "Deleting $rpm\n"; 155 155 $self->db->base->storage->txn_do( 156 156 sub { … … 166 166 my ($self, $rpm) = @_; 167 167 168 warn "$$ adding $rpm"; 168 -f $self->path . '/' . $rpm or return; 169 warn "Adding $rpm\n"; 169 170 my @stat = stat($self->path . '/' . $rpm); 170 171 eval { … … 199 200 }; 200 201 $header or do { 201 warn " $$ Cannot read " . $self->path . '/' . $rpm;202 warn "Cannot read " . $self->path . "/$rpm\n"; 202 203 return ""; 203 204 }; … … 208 209 )->get_column('pkgid')->all; 209 210 if ($find) { 210 warn "$$ Find";211 211 return($header->queryformat('%{PKGID}'), 0); 212 212 }
Note: See TracChangeset
for help on using the changeset viewer.