From c2ccf9289b42b508e0c80446593702660a511354 Mon Sep 17 00:00:00 2001 From: John Hyland Date: Tue, 30 Sep 2014 12:02:00 -0700 Subject: [PATCH] Fix pkill errors. Change originally authored by Tony Rice. Edited to include only the fix, and remove the version bump from this commit. --- lib/murder/admin.rb | 28 ++++++++++++++++++---------- lib/murder/murder.rb | 10 ++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/murder/admin.rb b/lib/murder/admin.rb index e636141..2f93324 100644 --- a/lib/murder/admin.rb +++ b/lib/murder/admin.rb @@ -1,10 +1,10 @@ -# Copyright 2010 Twitter, Inc. -# Copyright 2010 Larry Gadea -# Copyright 2010 Matt Freels -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at +# Copyright 2010 Twitter, Inc. +# Copyright 2010 Larry Gadea +# Copyright 2010 Matt Freels +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # @@ -39,18 +39,26 @@ run("SCREENRC=/dev/null SYSSCREENRC=/dev/null screen -dms murder_tracker python #{remote_murder_path}/murder_tracker.py && sleep 0.2", :pty => true) end + desc "If the Bittorrent tracker is running, this will kill the process. Note that if it is not running you will receive an error." task :stop_tracker, :roles => :tracker do - run("pkill -f 'SCREEN.*murder_tracker.py'") + pkill('SCREEN.*murder_tracker.py') end desc "Identical to stop_seeding, except this will kill all seeding processes. No 'tag' argument is needed." task :stop_all_seeding, :roles => :seeder do - run("pkill -f \"SCREEN.*seeder-\"") + pkill('SCREEN.*seeder-*') end desc 'Sometimes peers can go on forever (usually because of an error). This command will forcibly kill all "murder_client.py peer" commands that are running.' task :stop_all_peering, :roles => :peer do - run("pkill -f \"murder_client.py peer\"") + pkill('murder_client.py.peer*') end end + + +#Replaces pkill because this wont fail +def pkill(name) + run "ps -ef | grep #{name} | grep -v grep | awk '{print $2}' | xargs kill || echo 'no process with name #{name} found'" +end + diff --git a/lib/murder/murder.rb b/lib/murder/murder.rb index 95339bc..dc5c180 100644 --- a/lib/murder/murder.rb +++ b/lib/murder/murder.rb @@ -61,7 +61,7 @@ DESC task :stop_seeding, :roles => :seeder do require_tag - run("pkill -f \"SCREEN.*seeder-#{tag}\"") + pkill("SCREEN.*seeder-#{tag}") end desc <<-DESC @@ -102,7 +102,7 @@ task :stop_peering, :roles => :peer do require_tag - run("pkill -f \"murder_client.py peer.*#{filename}\"") + pkill("murder_client.py.peer*#{filename}") end task :clean_temp_files, :roles => [:peer, :seeder] do @@ -128,3 +128,9 @@ def require_tag set :filename, "#{tmp}/#{tag}.tgz" end end + +#Replaces pkill because this wont fail +def pkill(name) + run "ps -ef | grep #{name} | grep -v grep | awk '{print $2}' | xargs kill || echo 'no process with name #{name} found'" +end +