Fletcher Moore Fletcher Moore - 1 year ago 117
Ruby Question

How to execute a rake task using mina?

I want to run a rake task (migrate) contained in my Rakefile in my Sinatra app. I am using Mina to deploy.

rake migrate
works great if I run it on the server or on my development, but I cannot get Mina to execute the task.

My current deploy looks like this within

task :deploy => :environment do
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'

to :launch do
queue "sudo /opt/nginx/sbin/nginx -s reload"

I tried both
queue "rake migrate"
queue "#{rake} migrate"
within the deploy block and within the launch block but it always complains
bash: command not found

Answer Source

Mina uses ssh to run remote commands. That means that the commands run in a different environment as when you log in. This is causing problems with rvm and rbenv as they are not initialised properly. Luckily, mina has rvm support, you just have to set it up:

require 'mina/rvm'
task :environment do
  invoke :'rvm:use[ruby-1.9.3-p125@gemset_name]'

task :deploy => :environment do

You can do a similar thing for rbenv (documentation)