From 132dc0066dc23b0b34d583440593b7cb1139afb7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 3 Jul 2012 16:22:38 -0700 Subject: [PATCH] nuke: be more careful about kill; simplify If the archive dir is specified, make sure we are killing the right process. Also drop the kill_process helper; it's simple enough to open-code. --- teuthology/misc.py | 3 --- teuthology/nuke.py | 13 +++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index db3133cf97..33f9b51697 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -424,9 +424,6 @@ def get_clients(ctx, roles): def get_user(): return getpass.getuser() + '@' + socket.gethostname() -def kill_process(ctx): - subprocess.check_call(["kill", "-9", str(ctx.pid)]); - def read_config(ctx): filename = os.path.join(os.environ['HOME'], '.teuthology.yaml') ctx.teuthology_config = {} diff --git a/teuthology/nuke.py b/teuthology/nuke.py index 09a84f9111..b1f1baf0d9 100644 --- a/teuthology/nuke.py +++ b/teuthology/nuke.py @@ -33,7 +33,7 @@ def parse_args(): '-p','--pid', type=int, default=False, - help='pid of the process to be deleted', + help='pid of the process to be killed', ) parser.add_argument( '-r', '--reboot-all', @@ -262,7 +262,7 @@ def main(): if ctx.archive: ctx.config = config_file(ctx.archive + '/config.yaml') if not ctx.pid: - ctx.pid = int open(ctx.archive + '/pid').read().rstrip('\n') + ctx.pid = int(open(ctx.archive + '/pid').read().rstrip('\n')) if not ctx.owner: ctx.owner = open(ctx.archive + '/owner').read().rstrip('\n') @@ -276,8 +276,13 @@ def main(): ctx.owner = get_user() if ctx.pid: - from teuthology.misc import kill_process - kill_process(ctx) + if ctx.archive: + import os + os.system('grep -q %s /proc/%d/cmdline && kill %d' % (ctx.archive, + ctx.pid, + ctx.pid)) + else: + subprocess.check_call(["kill", "-9", str(ctx.pid)]); nuke(ctx, log, ctx.unlock, ctx.synch_clocks, ctx.reboot_all) -- 2.39.5