From: Bán M. <ba...@vo...> - 2010-09-07 09:53:15
|
On Tue, 7 Sep 2010 11:44:46 +0200 Michał Borychowski <mic...@ge...> wrote: > Please, send these two scripts to the list so that we can have a look > at them > > I start these scripts from the init.d on the masterserver: #!/usr/bin/perl use strict; use IO::Socket; use Net::hostent; my $mfsserver = '/usr/sbin/mfsmaster'; my $port = 7990; my $data_path = "/var/lib/mfs"; my ($server, $client, $hostinfo, $n, $foo, $buf); $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; system("$mfsserver start"); print "[mfsmaster server has been started]\n"; while ($client = $server->accept()) { $client->autoflush(1); $hostinfo = gethostbyaddr($client->peeraddr); while ( <$client>) { next unless /\S/; if (/^close$/i) { last; } elsif (/^(meta:)/) { $n = $'; chomp($n); $foo = `tail -1 $data_path/changelog.0.mfs`; chomp($foo); if ($n ne $foo) { system("$mfsserver restart"); open (FH,"<$data_path/metadata.mfs.back") or die $!; binmode(FH); while (sysread(FH, $buf, 1024)) { syswrite($client, $buf, length($buf)); } close(FH) or die $!; } } else { close $client; } } close $client; } on the metalogger server: #!/usr/bin/perl use strict; use IO::Socket; my $mfslogger = '/usr/sbin/mfsmetalogger'; my $data_path = "/var/lib/mfs"; my $host = "mfsmaster"; my $port = 7990; my ($kidpid, $handle, $buf, $c, $last_line); $last_line = `tail -1 $data_path/changelog_ml.0.mfs`; $handle = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $host, PeerPort => $port) or die "can't connect to port $port on $host: $!"; $handle->autoflush(1); die "can't fork: $!" unless defined($kidpid = fork()); if ($kidpid) { open (FH,">$data_path/metadata_ml.mfs.back") or die $!;; binmode(FH); $c = 0; while (sysread($handle, $buf, 1024)) { syswrite(FH, $buf, length($buf)); $c = $c+1; } close(FH); if ($c) { unlink glob("$data_path/changelog_ml*"); system("touch $data_path/changelog_ml.0.mfs"); exec("$mfslogger $ARGV[0]"); } kill("TERM", $kidpid); } else { print $handle "meta:$last_line\n"; print $handle "close\n"; } |