here's an example from our deployscripts where we use pkill

    desc "Force stop of delayed_job init scripts. This task is to be
run before deploy so it can do an orderly shutdown if possible. It
needs to be tolerant of the situation where the init scripts do not
exist yet."
    task :force_stop, :roles => :app do
      # Use stop script if available, follow up with killall.
      stop
      run "pkill -TERM -x -f '/usr/local/ruby-enterprise/bin/ruby
/usr/local/ruby-enterprise/bin/rake jobs:work'; true" #stop wasn't
killing delayed_jobs by itself in some circumstances.
    end


On Fri, Sep 18, 2009 at 8:58 AM, pete <[email protected]> wrote:
>
> I don't think I quite get what you mean.  I understand that if Tomcat
> is running and you bounce it, it will get a new PID.  But I am
> grepping for the currently running PID associated with Tomcat right?
>
> For example:
> .......
>  pid = capture("ps -aef | grep tomcat | head -2 | tail -1 | awk
> '{print $2}'")
>  run "kill -9 #{pid}"
> .......
>
>
>
> On Sep 18, 9:54 am, Lee Hambley <[email protected]> wrote:
>> It's a different pid every time your process starts, you must also bear in
>> mind that when grepping, sometimes you restrict the result of PS to include
>> the pid of the grep command filtering it
>> e.g: ps aux | grep ruby
>>
>> leehambley  1867   0.2  0.0  2425520     96 s000  R+    4:53pm   0:00.01
>> grep --color ruby
>> root       124   0.0  0.0  2445616    944   ??  S    Tue09pm   0:00.01
>> /opt/loca…..passenger….
>>
>> -- Lee Hambley
>>
>> Twitter: @leehambley
>> Blog:http://lee.hambley.name/
>> Working with Rails:http://is.gd/1s5W1
>>
>> 2009/9/18 pete <[email protected]>
>>
>>
>>
>>
>>
>> > I used Capture, which seems a bit cleaner, I don't have the ability to
>> > use pkill.
>>
>> > However, I get the wrong PID returned??
>>
>> > When I run my command on the command line manually I get 32553, as an
>> > example.
>>
>> > When Cap runs, it returns 32106, or something like that.
>>
>> > Why am I getting different PIDs?
>>
>> > On Sep 17, 7:45 pm, Donovan Bray <[email protected]> wrote:
>> > > Use capture instead of run
>> > > And parameterize the second command to use what was captured
>>
>> > > Or investigate pskill and killall that can do it in one step
>>
>> > > On Sep 17, 2009, at 11:28 AM, pete <[email protected]> wrote:
>>
>> > > > Let me clarify this a little better...
>>
>> > > > I would like to do something like this:
>>
>> > > > task :myTask, :roles => :myhost do
>> > > >                run "ps- -aef | grep <searchstring> | head -2 | tail
>> > > > -1 | awk '{print $2}'"
>> > > >                run "kill <PID FROM PREVIOUS run COMMAND>"
>> > > > end
>>
>> > > > On Sep 17, 11:57 am, pete <[email protected]> wrote:
>> > > >> Hi-
>>
>> > > >> I want to use Cap to kill a process, but I don't know the PID so I am
>> > > >> using what I have below to get it:
>>
>> > > >> ps- -aef | grep <searchstring> | head -2 | tail -1 | awk '{print $2}'
>>
>> > > >> Is it possible to use the results of the above command in a custom
>> > > >> task and kill off the PID that is returned?
>>
>> > > >> Thanks!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.co.uk/group/capistrano?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to