user141146
user141146

Reputation: 3315

ruby net/ssh failing to execute rake commands remotely

Hi I'm trying to use the ruby net/ssh gem (2.0.24) to connect to a remote server and run a rake task. I can run other simple tasks using the script outlined below, but rake is failing.

This is my code

Net::SSH.start("myremote_server", 'ubuntu', :keys => ['abcdef.pem'], :paranoid => false, :verbose => :debug) do |ssh|
  result = ssh.exec!("cd a_rails_directory; rake sunspot:solr:start")
  puts result
  ssh.loop
end

and I get the following error message

rake aborted!
uninitialized constant Bundler
/home/ubuntu/a_rails_directory/config/boot.rb:9:in `rescue in <top (required)>'
/home/ubuntu/a_rails_directory/config/boot.rb:5:in `<top (required)>'
/home/ubuntu/a_rails_directory/config/application.rb:1:in `<top (required)>'
/home/ubuntu/a_rails_directory/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

I can run the rake taks quite easily when I ssh-into the remote server manually, but it doesn't work with net/ssh as I've outlined above.

Somehow, I feel like I'm not connecting with the proper shell or the proper access to the path variables, but I'm not sure and I don't know how to fix it either. Any thoughts?

TIA

Upvotes: 2

Views: 1286

Answers (1)

user141146
user141146

Reputation: 3315

never mind. figured out how to load the relevant ruby path info

result = ssh.exec!("[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\" ; cd rails_directory; rake sunspot:solr:start")

Upvotes: 3

Related Questions