Last change
on this file since 29649 was 29649, checked in by jmt12, 9 years ago |
Perseus was an attempt to add functionality to automatically and remote fix Medusa is processes went run-away. The idea was the Persus server would either run as a daemon or be periodically called by cron, it would look for a sentinel file or be contacted by a client, and then it would slay processes belonging to a certain user. Never actually used, because the problems were found to be NFS/system level and impossible to solve without a hard reset anyway
|
-
Property svn:executable
set to
*
|
File size:
1.4 KB
|
Line | |
---|
1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 |
|
---|
6 | use IO::Socket::INET;
|
---|
7 |
|
---|
8 | print "===== Perseus Client =====\n";
|
---|
9 |
|
---|
10 | my $host = 'localhost';
|
---|
11 | my $port = 39875;
|
---|
12 | my $talk_time = 60; # Sixty second timeout
|
---|
13 | my $retry_time = 5;
|
---|
14 |
|
---|
15 | if (!defined $ARGV[0])
|
---|
16 | {
|
---|
17 | die("Usage: perseusclient.pl \"<cmd1> [<cmd2> ...]\"\n");
|
---|
18 | }
|
---|
19 | my @commands = split(/\s/, $ARGV[0]);
|
---|
20 |
|
---|
21 | print " * Sending commands to: " . $host . ":" . $port . "...\n";
|
---|
22 |
|
---|
23 | my $not_sent = 1;
|
---|
24 | while ($not_sent)
|
---|
25 | {
|
---|
26 | print " - connecting... ";
|
---|
27 | eval
|
---|
28 | {
|
---|
29 | local $SIG{ALRM} = sub { die 'timeout' };
|
---|
30 | alarm $talk_time;
|
---|
31 | my $socket = IO::Socket::INET->new(PeerHost => $host,
|
---|
32 | PeerPort => $port,
|
---|
33 | Proto => 'tcp'
|
---|
34 | );
|
---|
35 | if (defined $socket)
|
---|
36 | {
|
---|
37 | foreach my $command (@commands)
|
---|
38 | {
|
---|
39 | $socket->send($command . "\n") or die "couldn't send anything";
|
---|
40 | }
|
---|
41 | close($socket);
|
---|
42 | $not_sent = 0; # Sent successfully (hopefully)
|
---|
43 | print "sent!\n";
|
---|
44 | }
|
---|
45 | else
|
---|
46 | {
|
---|
47 | print "failed\n";
|
---|
48 | }
|
---|
49 | alarm 0; # reset alarm
|
---|
50 | };
|
---|
51 | alarm 0; # reset alarm
|
---|
52 | if (defined $@ && $@ ne '')
|
---|
53 | {
|
---|
54 | if ($@ =~ /timeout/)
|
---|
55 | {
|
---|
56 | print "timed out\n";
|
---|
57 | }
|
---|
58 | else
|
---|
59 | {
|
---|
60 | print "Error:" . $@ . "\n";
|
---|
61 | }
|
---|
62 | }
|
---|
63 | if ($not_sent)
|
---|
64 | {
|
---|
65 | print " - retrying in " . $retry_time . " seconds... \n";
|
---|
66 | sleep($retry_time);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | print "Commands sent!\n\n";
|
---|
71 |
|
---|
72 | exit;
|
---|
73 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.