fpghost fpghost - 1 year ago 301
Linux Question

Fabric nonzero return code 137

I have the following task in fabric, designed to brute force kill all celery workers in an emergency

def brute_kill_cel_workers():
with settings(sudo_user="operatore"):
sudo("sudo ps aux|grep 'celery worker'|awk '{print $2}'|xargs sudo kill -9")

It fails with

Fatal error: sudo() received nonzero return code 137 while executing!

Why is this? The commnd itself works fine from the an ssh shell as user "operatore" on the server. Or at least how can I get fabric to give me some more information to work with...

I've also tried just
sudo("ps aux|grep 'celery worker'|awk '{print $2}'|xargs kill -9")
run("sudo ps aux|grep 'celery worker'|awk '{print $2}'|xargs sudo kill -9")

Answer Source

As you killed Celery with SIGKILL (kill -9) you get that return code: 128 + 9 (see this list of exit codes).

If you check the return code when you run that command with ssh, you'll see the code is identical, but just not handled: when you execute echo $? (which shows the exit code of the last commend) after executing the command line with ssh, you'll get 137 as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download