Article View: news.software.nntp
Article #74425Re: inn2-ssl and lots of idle connections
From: Russ Allbery
Date: Mon, 23 Oct 2006 15:49
Date: Mon, 23 Oct 2006 15:49
204 lines
7574 bytes
7574 bytes
Jeffrey M Vinocur <jeff@litech.org> writes:
> Right, the current TLS implementation does not support timeouts at all;
> this is on our TODO list but will probably not be fixed anytime soon.
And, for reasons that I've never managed to figure out, the regular nnrpd
timeouts don't work for my reader server under stunnel either. That may
be because I'm a few revisions back on 2.4, though, on that system (I keep
meaning to get around to upgrading).
Anyway, here's a script that comes in handy for all sorts of things like
this. Will only work on systems that support SysV ps syntax (Linux
included).
#!/usr/bin/perl
$ID = q$Id: okill,v 1.3 2006-09-20 20:43:28 eagle Exp $;
#
# okill -- Kill processes that have been running longer than certain hours.
#
# Written by Susan Feng
# Copyright 2005, 2006, Board of Trustees, Leland Stanford Jr. University
##############################################################################
# Modules and declarations
##############################################################################
use strict;
use vars qw($ID $PS $LIMIT);
use Getopt::Long qw(GetOptions);
# The syntax of this ps command should work across all SYSV platforms.
$PS = 'ps -e -o pid,ppid,user,etime,time,pcpu,comm';
# Default to killing jobs running for longer than 24 hours.
$LIMIT = 24;
##############################################################################
# Helper routines
##############################################################################
# Calculate the number of minutes from the [dd-]hh:mm:ss format used by the
# etime and cputime fields of ps.
sub calc_minutes {
my $time = shift;
$time =~ /^((\d+)-)?((\d+):)?(\d+):(\d+)$/;
my ($days, $hours, $mins, $secs) = ($2, $4, $5, $6);
$hours += $days * 24 if $days;
$mins += $hours * 60 if $hours;
return $mins;
}
##############################################################################
# Main routine
##############################################################################
# Always flush output and fix executable name.
$| = 1;
$0 =~ s%^.*/%%;
# Define the default signal type and limits.
my $signal = 1;
my ($etime_lim, $time_lim, $pcpu_lim) = (0, 0, 0);
# Parse command-line options.
Getopt::Long::config ('bundling');
my ($help, $dryrun, $verbose, $version, $parent);
GetOptions ('h|help' => \$help,
'e|etime=i' => \$etime_lim,
't|time=i' => \$time_lim,
'c|pcpu=i' => \$pcpu_lim,
'n|dryrun' => \$dryrun,
'p|parent' => \$parent,
's|signal' => \$signal,
'verbose' => \$verbose,
'v|version' => \$version) or exit 1;
if ($help) {
print "Feeding myself to perldoc, please wait....\n";
exec ('perldoc', '-t', $0);
} elsif ($version) {
my $version = join (' ', (split (' ', $ID))[1..3]);
$version =~ s/,v\b//;
$version =~ s/(\S+)$/($1)/;
die $version, "\n";
}
die "Usage: $0: okill [-etime <minutes>] [-n] [-p] procname\n"
unless my $procname = shift @ARGV;
# Always be verbose if we are doing a dry run.
$verbose = 1 if $dryrun;
# Open up the process list and start reaping the old ones.
open (PROCS, "$PS |") or die "$0: unable to run $PS\n";
my ($pid, $ppid, $user, $etime, $time, $pcpu, $comm);
while (<PROCS>) {
s/^\s+//;
($pid, $ppid, $user, $etime, $time, $pcpu, $comm) = split /\s+/;
next unless $comm =~ /^(.*\/)?$procname$/;
$etime = calc_minutes($etime);
$time = calc_minutes($time);
if ($etime >= $etime_lim && $time >= $time_lim && $pcpu >= $pcpu_lim) {
if ($verbose) {
print "killing $pid age $etime minutes\n";
print "killing parent $ppid age $etime minutes\n" if $parent;
}
unless ($dryrun) {
kill $signal, $pid unless $pid == 1;
kill $signal, $ppid if $parent and $ppid != 1;
}
}
}
close (PROCS);
##############################################################################
# Documentation
##############################################################################
=head1 NAME
okill - Kill processes that have exceed certain limits
=head1 SYNOPSIS
B<okill> [B<-h>] [B<-v>]
B<okill> [B<--etime> I<minutes>] [B<-np>] [B<-s> I<signal>] <process name>
=head1 DESCRIPTION
okill takes a process name on the command line and finds all the processes
with that name and kills those exceeding certain limits. This script
should run all System V compliant operating systems. The init process
will never be killed. The current supported limits are etime,
time, and pcpu. See the OPTIONS section to see what these limits mean.
If more than one limit is supplied, then all the limits have to be
exceeded to avoid unnecessary killing. If no limits are supplied, then
this script will kill all processes matching the command name (like the
pkill behavior).
=head1 OPTIONS
=over 4
=item B<-c> I<pcpu>, B<--pcpu>=I<percentage>
Kill matching processes that exceed the supplied cpu utilization. pcpu
stands for the cumulative CPU time divided by the elapsed time.
=item B<-e> I<minutes>, B<--etime>=I<minutes>
Kill matching processes that have been running longer than the supplied
number of minutes. etime stands for elapsed time.
=item B<-h>, B<--help>
Print out this documentation (which is done simply by feeding the script to
C<perldoc -t>).
=item B<-n>
Dry run only. Print out what would be killed. If [B<-p>] is given will
also print the parent process id. Implies [B<--verbose>].
=item B<-p>, B<--parent>
Kill the parent process as well. This is fairly dangerous.
=item B<-s> I<signal>, B<--signal>=I<signal>
By default, B<okill> sends signal 1 (HUP). To specify a different signal,
use this flag. The signal must be a number. (15, TERM, is a common
choice.)
=item B<-t> I<minutes>, B<--time>=I<minutes>
Kill matching processes that exceed the supplied cumulative CPU time.
=item B<--verbose>
Verbose. Print out what would be killed.
=item B<-v>, B<--version>
Print the version of B<okill> and exit.
=back
=head1 AUTHORS
Susan Feng,
Huaqing Zheng
=cut
--
Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>
Please post questions rather than mailing me directly.
<http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Technical Details
Message-ID:
<87pscj9gmo.fsf@windlord.stanford.edu>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!headwall.stanford.edu!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mailReferences:
<eh657r$knl$1@guepard.ecp.fr> <eh74i8$inj$4@puck.litech.org>Show Full Headers
Complete Article Headers
Message-ID: <87pscj9gmo.fsf@windlord.stanford.edu> Subject: Re: inn2-ssl and lots of idle connections Date: Mon, 23 Oct 2006 08:49:35 -0700 From: Russ Allbery <rra@stanford.edu> References: <eh657r$knl$1@guepard.ecp.fr> <eh74i8$inj$4@puck.litech.org> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!headwall.stanford.edu!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mail Newsgroups: news.software.nntp Organization: The Eyrie Lines: 204 NNTP-Posting-Host: windlord.stanford.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.Stanford.EDU 1161618575 21720 171.64.19.147 (23 Oct 2006 X-Complaints-To: news@news.stanford.edu User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.19 (linux) Cancel-Lock: sha1:3Ko4pvaBuHQZWB+RJ2emfbMuzmY=