[capistrano] Capistrano failing on pkill-related tasks?

232 views
Skip to first unread message

Christopher Opena

unread,
Apr 17, 2010, 4:52:11 AM4/17/10
to capis...@googlegroups.com
Hello all, I'm doing some experimentation on using pkill inside of Capistrano to kill multiple processes at once.  I'm performing the pkill inside of a bash (sudo "if [cond]; then pkill #{process} fi") conditional.  For troubleshooting's sake, I'm making sure the [cond] prints out the output.  No problems there, the if [cond] finds and prints out the process and pkill actually does kill the process when it's found, but then Capistrano exits out with a:

command finished
command "pkill #{process}" failed on #{server_name}

Has anyone experienced a problem like this before?

I even tried pulling the sudo bash command out of Capistrano and into a bash script and then having Capistrano run the script (sudo "/path/to/script"), and it runs it successfully and I see the task getting killed, but the Cap exists with:

command finished
command "sudo /path/to/script" failed on #{server_name}

Anyone have any ideas?  This one is really strange, and I'm a bit stumped.  Although it's successful in the end, it makes it hard to place the task in the middle of a long string of tasks because it exits out and doesn't continue :/

Thanks in advance,
-Chris.

--
* You received this message because you are subscribed to the Google Groups "Capistrano" group.
* To post to this group, send email to capis...@googlegroups.com
* To unsubscribe from this group, send email to capistrano+...@googlegroups.com For more options, visit this group at http://groups.google.com/group/capistrano?hl=en

Lee Hambley

unread,
Apr 18, 2010, 5:13:05 AM4/18/10
to capis...@googlegroups.com
Chris,

That's triggered by the posix return code of, in this case pkill or your conditional statement. I suggest adding something like a `&& true`; so it alwasy returns a `sucess` code.

- Lee

Francis Fish

unread,
Aug 7, 2013, 4:16:50 PM8/7/13
to capis...@googlegroups.com
Hi guys

Just in case someone reads this again ... cap is running

sh -c 'pkill -f fred'

which means the shell will be killed because it matches fred, so it always returns false. 

See, for example:

$ pgrep -f nunu
$ sh -c 'pgrep -f nunu'
16431

Which finds the sh with those args

sh -c 'exec $(pkill nunu || true)'

Will do what you want because the shell is replaced by the exec command.

Not sure if this is an issue for cap 3.

Francis Fish

unread,
Aug 7, 2013, 4:24:02 PM8/7/13
to capis...@googlegroups.com
Previous post works with sh -c but still not with cap 2 ...


On Sunday, 18 April 2010 10:13:05 UTC+1, Lee Hambley wrote:

Donovan Bray

unread,
Aug 12, 2013, 11:33:26 AM8/12/13
to capis...@googlegroups.com
sudo "pkill -f [f]red"

Will also work. Because pkill is good about not killing its own pid, but as pointed out doesn't prevent killing the parent shell running pkill where "fred" will also be found. 

The above uses a regex of looking for an "f" followed by "red", and since the shell now shows "[f]red" it does not match and won't be killed. 
--
--
* You received this message because you are subscribed to the Google Groups "Capistrano" group.
* To post to this group, send email to capis...@googlegroups.com
* To unsubscribe from this group, send email to capistrano+...@googlegroups.com For more options, visit this group at http://groups.google.com/group/capistrano?hl=en
---
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages