Hi Noman,

  You can do it using shellscript:

task :check_tomcat_status, :roles => :app do
    run "#{sudo} /usr/local/sbin/check_tomcat_status.sh"
    run "sleep 15s"
end


Being check_tomcat_status.sh a shell script that check, i.e., if service
tomcat6 exists and do the work else do the work with tomcat5


   Another option could be define the role with tomcat5 and tomcat6
modifier:

role :app, "127.0.0.1", :tomcat5 => true
role :app, "127.0.0.2", :tomcat6 => true


   Later define the task:

task :check_tomcat_status, :roles => :app do
    run "#{sudo} /sbin/service tomcat5 status", :only => {:tomcat5 => true}
    run "#{sudo} /sbin/service tomcat6 status", :only => {:tomcat6 => true}
    run "sleep 15s"
end


Regards

Note: The sudo use as run command is deprecated, last
paragraph<https://github.com/capistrano/capistrano/wiki/2.x-DSL-Action-Invokation-Sudo>
[1]

[1]
https://github.com/capistrano/capistrano/wiki/2.x-DSL-Action-Invokation-Sudo

2012/2/8 Noman Amir Jamil <[email protected]>

> Hi All,
>
> I was wondering if it is possible to include a conditional check in task
> definition. For example, I have a task defined:
>
>
> task :check_tomcat6_status, :roles => :app do
>     sudo "/sbin/service tomcat6 status"
>     run "sleep 15s"
> end
>
> I want to introduce a conditional hosts check in it, like:
>
> if :hosts = host1 then
>    sudo "/sbin/service tomcat5 status"
> else
>   sudo "/sbin/service tomcat6 status"
> fi
>  run "sleep 15s"
> end
>
> Can someone help me with the correct syntax for this scenario?
>
> Thanks
> Noman A.
>
>  --
> * 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.com/group/capistrano?hl=en

-- 
* 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.com/group/capistrano?hl=en

Reply via email to