I am moving my Rails application deploy from Capistrano to Mina. The only thing left to do is writing a task to restart a server. I already did the part to start server, but I can't understand how to stop it.
When I was using Capistrano, I had the following task:
desc 'Stop Unicorn'
task :stop do
on roles(:app) do
if test("[ -f #{fetch(:unicorn_pid)} ]")
execute :kill, capture(:cat, fetch(:unicorn_pid))
end
end
end
This, as I understood, firstly runs test
command to determine whether file exists, and then runs kill command if needed. I understand how to do everything of this in Mina except of how to execute test
function on server and get its result to do something with it.
Here is what I'm using now,
task :restart_server => :environment do
queue "cd #{deploy_to}/current"
if File.exists? unicorn_pid
queue "kill `cat #{unicorn_pid}`"
end
queue "bundle exec unicorn -c #{deploy_to}/#{shared_path}/config/unicorn.rb -E production -D"
end
but this does not work, and I think I understand why (because the File.exists
string is executed on client side, not server side).
So, what should I do?
Decided it will be easier to just run test
function from queue
, like that:
task :restart_server => :environment do
queue "cd #{deploy_to}/current"
queue "[ -f #{unicorn_pid} ] && kill $(cat #{unicorn_pid})"
queue "bundle exec unicorn -c #{deploy_to}/#{shared_path}/config/unicorn.rb -E production -D"
end