Web reaper


These days I had working on web interfaces for some Perl scripts, the server is an 8-cores Linux box with CentOS with Apache as web server, but some tests didn't work well and some probably fall into an infinite loops. The problem was I can not kill these process, because I must not know the admin password and I can not have access for the web server, the scripts are created in my home and when activate the process is submit by the apache user. So the solution was a script which ask the PID and send a termination signal. Here is the code, maybe someone can use it:



#!/tools64/bin/perl -w
use strict;

=head1 NAME

reaperl.pl

=head1 DESCRIPTION

Web service to stop some uncontrolled process created by the Perl::CGI.
Simply presents a web form to indicate the PID and call a system termination.

=cut

use CGI::Pretty qw/:standard/;

print header;
print start_html(-title=>'reaperl.pl');
print start_form;
print p('Kill this process: ', textfield(-name=>'proc'));
print submit(), reset();
print end_form;

if( param()) {
my $proc = param('proc');
$proc =~ s/\D//g;
my $res = `kill -15 $proc`;
print p("Killed $proc: $res");
}
print end_html;

=head1 AUTHOR

Juan Caballero (linxe _at_ glib.org.mx)

=head1 LICENSE

Perl Artistic License (http://dev.perl.org/licenses/artistic.html)

=cut


Thanks to G for the idea.

Comments

Popular posts from this blog

PS3 cluster

Ubuntu Cluster - Slave nodes