summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpbuetow <puppet@mx.buetow.org>2012-03-14 23:57:37 +0100
committerpbuetow <puppet@mx.buetow.org>2012-03-14 23:57:37 +0100
commit772e0dce07faf123f7657d3161bff0ee6e9951e6 (patch)
tree3729e51b0cadb5e618877c7da2e025dd237440ed
parente5ac5b44c303cb4bc3e73770871387dc090a10b4 (diff)
instant shutdown works on debian squeeze
-rw-r--r--BUGS3
-rw-r--r--CHANGELOG3
-rwxr-xr-xloadbars47
3 files changed, 31 insertions, 22 deletions
diff --git a/BUGS b/BUGS
index 1305227..40b75cd 100644
--- a/BUGS
+++ b/BUGS
@@ -1,2 +1 @@
-* After quit ssh processes don't shut down instantly. But this is not an issue
- since whey will quit automatically after 'samples' times.
+* No known bugs ATM
diff --git a/CHANGELOG b/CHANGELOG
index dbf9b0a..d44fe5b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,5 @@
* Dropped FreeBSD support / focus is Linux
-* Instant terminating of sub-processes on shutdown. Requires
- Proc::ProcessTable Perl module.
+* On shutdown all sub-processes are gonna be terminated instantly (was old bug)
Sat Feb 25 20:09:02 CET 2012
* Release v0.5.1
diff --git a/loadbars b/loadbars
index 30a182b..de394e6 100755
--- a/loadbars
+++ b/loadbars
@@ -59,6 +59,7 @@ use constant {
$| = 1;
+my @PIDS : shared;
my %AVGSTATS : shared;
my %CPUSTATS : shared;
my %MEMSTATS : shared;
@@ -187,6 +188,27 @@ sub write_config () {
close $conffile;
}
+sub terminate_pids (@) {
+ my @threads = @_;
+
+ display_info 'Terminating sub-processes';
+ $_->kill('TERM') for @threads;
+ for my $pid (@PIDS) {
+ my $proc_table = Proc::ProcessTable->new();
+ for my $proc (@{$proc_table->table()}) {
+ if ($proc->ppid == $pid) {
+ display_info "Terminating PID ".$proc->pid;
+ kill 'TERM', $proc->pid if $proc->ppid == $pid;
+ }
+ }
+
+ display_info "Terminating PID $pid";
+ kill 'TERM', $pid;
+ }
+
+ display_info 'Terminating down. I\'ll be back!';
+}
+
sub stats_thread ($;$) {
my ( $host, $user ) = @_;
$user = defined $user ? "-l $user" : '';
@@ -194,7 +216,6 @@ sub stats_thread ($;$) {
my ($sigusr1, $sigterm) = (0,0);
my $loadavgexp = qr/(\d+\.\d{2}) (\d+\.\d{2}) (\d+\.\d{2})/;
my $inter = INTERVAL;
- my $pid;
until ($sigterm) {
my $bash = <<"BASH";
@@ -216,12 +237,14 @@ BASH
? $bash
: "ssh $user -o StrictHostKeyChecking=no $C{sshopts} $host '$bash'";
- $pid = open my $pipe, "$cmd |" or do {
+ my $pid = open my $pipe, "$cmd |" or do {
say "Warning: $!";
sleep 3;
next;
};
+ push @PIDS, $pid;
+
# Toggle CPUs
$SIG{USR1} = sub { $sigusr1 = 1 };
$SIG{TERM} = sub { $sigterm = 1 };
@@ -230,7 +253,7 @@ BASH
# 1=cpu, 2=mem, 3=net
my $mode = 0;
- while (<$pipe>) {
+ while (<$pipe>) {
chomp;
if ($mode == 0) {
@@ -265,23 +288,14 @@ BASH
# TODO: Use index instead of regexp for cpuregexp
$cpuregexp = qr/$I{cpuregexp}/;
$sigusr1 = 0;
+
} elsif ($sigterm) {
+ close $pipe;
last;
}
}
}
- my $proc_table = Proc::ProcessTable->new();
- for my $proc (@{$proc_table->table()}) {
- if ($proc->ppid == $pid) {
- display_info "Terminating PID $proc->ppid";
- kill 'TERM', $proc->pid if $proc->ppid == $pid;
- }
- }
-
- display_info "Terminating PID $pid";
- kill 'TERM', $pid;
-
return undef;
}
@@ -452,10 +466,7 @@ sub main_loop ($@) {
display_info 'Toggled number/hostname display';
} elsif ( $key_name eq 'q' ) {
- display_info 'Shutting down sub-processes';
- $_->kill('TERM') for @threads;
- sleep 1;
- display_info 'Shutting down done';
+ terminate_pids @threads;
$quit = 1;
return;