#!/usr/bin/perl use common::sense; use DBI; use POSIX qw(SIGTERM); print "Status: 200\nContent-Type: text/plain\n\n"; $|=1; $|=0; # flush my $dbh=DBI->connect('dbi:Pg:dbname=r2', 'ipp', undef, {RaiseError=>1}); sub sig { my $db2=DBI->connect('dbi:Pg:dbname=r2', 'postgres', undef, {RaiseError=>1}); my $st2=$db2->prepare('select pg_cancel_backend(?)'); $st2->execute($dbh->{pg_pid}); if( !$st2->fetchrow_arrayref->[0] ) { warn "couldn't stop backend PID=$dbh->{pg_pid}\n"; } exit 1; } POSIX::sigaction(SIGTERM, POSIX::SigAction->new(\&sig)) or die or setting SIGTERM handler: $!\n"; my $sth=$dbh->prepare('select burncpu(?)'); $sth->execute((($ENV{QUERY_STRING}+0) || .5).'s'); while( my $row=$sth->fetchrow_arrayref ) { print "@$row\n"; }