I was deploying my Symfony2 application on one server only for a few month and it was perfect, but as I've added more servers, I'm stuck when I want to update all my servers at the same time, but run some commands only once (like database migration, and assets generation and push to S3).
Here are my servers:
server '192.168.0.100', user: 'ubuntu', roles: %w{app db web toto}
server '192.168.0.101', user: 'ubuntu', roles: %w{app db web}
And here is one custom task I have in my deploy.rb
:
namespace :specific do
task :command do
on roles(:all) do |host|
if host.roles.include?(:toto)
invoke 'symfony:console', 'one:specific:command'
end
end
end
end
With cap --roles=toto staging deploy
but then only one of my two servers were updated.
I've tried the filter method like that:
namespace :assets do
task :increment do
set :filter, :roles => %w{toto}
invoke 'symfony:console', 'one:specific:command'
end
end
And other methods, copy pasting from stack overflow answers, but didn't found any matching answer š
I might have hesitated longer, as this answer is not working. And I'm still unable to find a solution, in any other post, SO question, or Capistrano documentation... š
I hesitated to post this question and finally found my answer. But as it took me a long search, here is the answer:
Just add primary: true
to one website :
server '192.168.0.100', roles: %w{app db web}, primary: true
server '192.168.0.101', roles: %w{app db web}
And in the deploy.rb
:
namespace :specific do
task :command do
on primary(:web) do
invoke 'symfony:console', 'one:specific:command'
end
end
end
My command output is still specifying the two servers, but hopefully only one did the specific command:
03 php app/console one:specific:command
ā 03 [email protected] 1.153s
ā 03 [email protected] 6.551s
Finally!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With