How to get the final command to be executed by sshkit

191 views Asked by At

I want to create a gem that has de ability to take a task and wrap all commands in another command.

For example, the capistrano3-unicorn gem unicorn:start task will execute on the server something like bundle exec unicorn -c unicorn.rb -E production, but the execute method is wrapped by a within method, so the command to be executed on the server will be something like cd /home/deploy/application/myapp/current && bundle exec unicorn -c unicorn.rb -E production

I want to be able to create a rake task that takes that unicorn:start task and wrap it inside another task.

For example if I want to create an upstart config file for the app, I could adds this command to a upstart.conf template and the run service my-unicorn-app start

That would be a use case I'm trying to pursue.

In SSHKit formatters the write command is called with a command arg that have what I'm looking for. But I need this at capistrano task level.

Thanks

1

There are 1 answers

0
Isaac Betesh On

I think what you're asking is how to access the exact command that is sent via SSH. What you're looking for is the #command method, on the return value of which you can call #to_command. Since #command is a private method, we need to use #send.

namespace :unicorn
  task :set_restart_command do
    on(roles(:web)) do
      within release_path do
        set(:unicorn_start_command, 
          send(:command, :unicorn, "-c unicorn.rb -E production").to_command)
      end
    end
  end  
end

Now, in another task, you can use fetch(:unicorn_start_command)