/[Sack]/trunk/lib/Sack/Server.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Sack/Server.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 270 by dpavlin, Mon Feb 15 09:40:12 2010 UTC revision 277 by dpavlin, Fri May 7 09:15:36 2010 UTC
# Line 49  sub fork_ssh { Line 49  sub fork_ssh {
49                  # parent                  # parent
50                  $info->{forked}->{$port} = $pid;                  $info->{forked}->{$port} = $pid;
51                  $info->{pending}->{$port} = 'forked';                  $info->{pending}->{$port} = 'forked';
52                    $info->{host}->{$port} = $host;
53                  return $port;                  return $port;
54    
55          } elsif ( ! defined $pid ) {          } elsif ( ! defined $pid ) {
56                  warn "can't fork $host $port";                  warn "can't fork $host $port";
57                  return;                  return;
58            } elsif ( $host =~ m/^(127.0.0.1|localhost)$/ ) {
59                    warn "# localhost, just execute node\n";
60                    exec $node_path, $port, $listen_port;
61          } else {          } else {
62                  # child                  # child
63                  warn "[$port] cpio last version\n";                  warn "[$port] cpio last version\n";
# Line 135  sub load_shard { Line 139  sub load_shard {
139    
140                          warn ">>>> [$port] bulk_load ", $#shards + 1, " shards\n";                          warn ">>>> [$port] bulk_load ", $#shards + 1, " shards\n";
141                          Storable::store_fd( { bulk_load => [ @shards ] }, $sock );                          Storable::store_fd( { bulk_load => [ @shards ] }, $sock );
142                            my $current = 0;
143                            my $total = $#shards + 1;
144                          foreach my $s ( @shards ) {                          foreach my $s ( @shards ) {
145                                  warn ">>>> [$port] bulk_load $s\n";                                  warn ">>>> [$port] bulk_load $s $current/$total\n";
146                                  Storable::store_fd( Storable::retrieve( $s ), $sock );                                  Storable::store_fd( Storable::retrieve( $s ), $sock );
147                                    $current++;
148                          }                          }
149                          warn ">>>> [$port] bulk_load finished\n";                          warn ">>>> [$port] bulk_load finished, $current shards\n";
150                          exit;                          exit;
151                  }                  }
152    
# Line 214  while (1) { Line 221  while (1) {
221                                                  }                                                  }
222                                          };                                          };
223                                          warn "ERROR: $@" if $@;                                          warn "ERROR: $@" if $@;
224                                    } elsif ( $method =~ m{^/favicon.ico} ) {
225                                            print $send "HTTP/1.0 200 OK\r\nContent-Type: image/vnd.microsoft.icon\r\n\r\n", read_file( 'artwork/favicon.ico' );
226                                            return 1;
227                                    } elsif ( $method =~ m{/nodes} ) {
228                                            to_all { ping => 1 };
229                                            my @proc = ( 'MemTotal', 'MemFree', 'Buffers', 'Cached', 'VmSize', 'VmPeak' );
230                                            print $send "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n",
231                                                    '<table><tr><th>', join('</th><th>', 'node', 'ip', @proc), '</th></tr>';
232                                            foreach my $node ( sort {
233                                                    $info->{host}->{$a} cmp $info->{host}->{$b} || # ip
234                                                    $a <=> $b # node
235                                            } keys %{$info->{proc}} ) {
236                                                    print $send '<tr><td>', join('</td><td align=right>',
237                                                            $node, $info->{host}->{$node}, map {
238                                                                    my $kb = $info->{proc}->{$node}->{$_};
239                                                                    $kb =~ s/\s+kb//i; $kb;
240                                                            } @proc ), '</td><tr>';
241                                            }
242                                            print $send '</table>';
243                                            return 1;
244                                  }                                  }
245    
246                                  my $refresh = $param->{refresh};                                  my $refresh = $param->{refresh};
# Line 308  while (1) { Line 335  while (1) {
335    
336                                  print $send qq|<h1>Nodes</h1>|;                                  print $send qq|<h1>Nodes</h1>|;
337                                  foreach my $node ( sort keys %{ $info->{forked} } ) {                                  foreach my $node ( sort keys %{ $info->{forked} } ) {
338                                          my $attr = '';                                          my $attr = qq| title="$info->{host}->{$node}"|;
339                                          if ( my $pending = $info->{pending}->{$node} ) {                                          if ( my $pending = $info->{pending}->{$node} ) {
340                                                  $attr .= qq| class="$pending"|;                                                  $attr .= qq| class="$pending"|;
341                                          }                                          }
342                                          print $send qq|<tt$attr>$node</tt>\n|;                                          print $send qq|<tt$attr>$node</tt>\n|;
343                                  }                                  }
344                                    print $send qq|<a href=/nodes/>details</a>|;
345    
346                                  print $send qq|<h1>Shards</h1><ul>|;                                  print $send qq|<h1>Shards</h1><ul>|;
347                                  foreach my $path ( glob '/tmp/sack/*' ) {                                  foreach my $path ( glob '/tmp/sack/*' ) {
# Line 381  while (1) { Line 409  while (1) {
409                                          Storable::store_fd( $response, $sock );                                          Storable::store_fd( $response, $sock );
410                                  } elsif ( $data->{ping} ) {                                  } elsif ( $data->{ping} ) {
411                                          my $port = $data->{port};                                          my $port = $data->{port};
412                                          delete( $info->{pending}->{$port} ) if $info->{pending}->{$port} eq 'forked';                                          delete( $info->{pending}->{$port} ) if defined $info->{pending}->{$port} && $info->{pending}->{$port} eq 'forked';
413                                          $session->{port}->{ $data->{port} } = $sock;                                          $session->{port}->{$port} = $sock;
414                                            foreach my $name ( keys %{$data->{proc}} ) {
415                                                    if ( $name eq 'loadavg' ) {
416                                                            $info->{proc}->{$port}->{loadavg} = [ split(/\s+/, $data->{proc}->{$name}) ];
417                                                    } else {
418                                                            foreach my $line ( split(/\n/,$data->{proc}->{$name}) ) {
419                                                                    my ($n,$v) = split(/:\s+/,$line);
420                                                                    $info->{proc}->{$port}->{$n} = $v;
421                                                            }
422                                                    }
423                                            }
424                                  } elsif ( defined $data->{load} && $data->{load} eq 'shard' ) {                                  } elsif ( defined $data->{load} && $data->{load} eq 'shard' ) {
425                                          if ( my $path = shift @shard_load_queue ) {                                          if ( my $path = shift @shard_load_queue ) {
426                                                  $info->{shard}->{$path} = 'read';                                                  $info->{shard}->{$path} = 'read';

Legend:
Removed from v.270  
changed lines
  Added in v.277

  ViewVC Help
Powered by ViewVC 1.1.26