How to run pt-kill from cron

861 views
Skip to first unread message

Atle

unread,
Jan 25, 2012, 1:14:58 AM1/25/12
to Percona Discussion
Unless I am missing something, pt-kill refuses to run from cron as it
requires STDIN to be available.

This is the command I run: PTDEBUG=1 /usr/local/bin/pt-kill --config /
etc/percona-toolkit/pt-kill-cleaner.conf

The config contains these non-sensitive pieces of information:
daemonize
log=/var/log/pt-kill.log
print
kill
pid=/var/run/pt-kill.pid
match-user=foobar
match-command=Query
busy-time=5
idle-time=30
interval=2
victims=all
wait-after-kill=2

Executed from the shell, the command runs fine and the process
daemonizes as expected.

Executed from crontab, the command runs one iteration and then exits.
Some of the output:
# pt_kill:3810 16106 Reading files -
..
# pt_kill:3810 16106 Checking processlist
# pt_kill:3810 16106 Processlist returned no queries
# pt_kill:3810 16106 Checking processlist
# pt_kill:3810 16106 /usr/local/bin/pt-kill ending
# Daemon:1631 16106 Removed PID file

As STDIN is not available to it the process tries to read STDIN,
fails, then exits.

The same behavior exhibits for both daemonize and without.

Jervin R

unread,
Feb 8, 2012, 8:11:48 AM2/8/12
to Percona Discussion
Why do you need to do it from cron - pt-kill is like a watchdog
process keeping an eye on processlist. IMHO, its better to keep it
always running instead of running from time to time, the latter can
miss or be delayed in killing a process. Also, if you use daemonize on
cron and pt-kill works as you expected you'll get a number of pt-kill
processes running!

Daniel Nichter

unread,
Feb 8, 2012, 10:21:54 AM2/8/12
to percona-d...@googlegroups.com
This was fixed in Percona Toolkit 2.0.3: https://bugs.launchpad.net/percona-toolkit/+bug/894255

> --
> You received this message because you are subscribed to the Google Groups "Percona Discussion" group.
> To post to this group, send email to percona-d...@googlegroups.com.
> To unsubscribe from this group, send email to percona-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/percona-discussion?hl=en.
>

Filippo

unread,
Feb 9, 2012, 11:25:55 PM2/9/12
to Percona Discussion
Hi Daniel,

I am running the latest version of pt-kill (2.0.3) on Solaris 10 and I
have the same issue.

I believe the problem is related to this check:
pt-kill:3546
if ( !-t STDIN ) {
PTDEBUG && _d("STDIN is piped");
@ARGV = ('-');
}

No matter if I specified "--daemonize", STDIN is not /dev/tty then the
code:
pt-kill:3590
if ( @ARGV ) {
PTDEBUG && _d('Getting processlist from files:', @ARGV);

is executed instead of the expected:
pt-kill:3626
else {
PTDEBUG && _d('Getting processlist from MySQL');


I am not a PERL developer but I believe something like this should fix
this issue:
- if ( !-t STDIN ) {
+ if ( !$o->get('daemonize') && !-t STDIN ) {


Cheers
Filippo

Daniel Nichter

unread,
Feb 10, 2012, 10:50:31 AM2/10/12
to percona-d...@googlegroups.com
Filippo,

You are correct. This was fixed in https://code.launchpad.net/~percona-toolkit-dev/percona-toolkit/fix-stdin-bug-894255 but that branch was not merged, therefore it was not actually in 2.0.3. Sorry for the confusion. I'll merge this branch and it will be released for real in 2.0.4. Until then, I'll reply with a download link for the updated pt-kill once it's merged...

-Daniel

Daniel Nichter

unread,
Feb 10, 2012, 11:22:36 AM2/10/12
to percona-d...@googlegroups.com
This is now in the 2.0 branch: http://bazaar.launchpad.net/~percona-toolkit-dev/percona-toolkit/2.0/view/head:/bin/pt-kill

There's a download link on that page. Note that generally we don't suggest downloading directly from trunk because the code is frequently changing, but in this particular case, I don't foresee any serious changes to pt-kill. When this is released in 2.0.4, early next month probably, you should get the official release, too.

-Daniel

Reply all
Reply to author
Forward
0 new messages