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
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")
Related
Trying to run some Watir code as a Rake task that is giving me this error:
$ bundle exec rake update_market_rents:market_rents
DL is deprecated, please use Fiddle
(in C:/Users/310046998/sites/testpropinvest)
rake aborted!
LoadError: cannot load such file -- watir-webdriver
C:/Users/310046998/sites/testpropinvest/vendor/bundle/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
C:/Users/310046998/sites/testpropinvest/vendor/bundle/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
C:/Users/310046998/sites/testpropinvest/vendor/bundle/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
C:/Users/310046998/sites/testpropinvest/vendor/bundle/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
C:/Users/310046998/sites/testpropinvest/lib/tasks/update_market_rents.rake:10:in `block (2 levels) in <top (required)>'
C:/Users/310046998/sites/testpropinvest/vendor/bundle/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => update_market_rents:market_rents
(See full trace by running task with --trace)
Code:
namespace :update_market_rents do
desc "TODO"
task market_rents: :environment do
#watir code
require 'watir-webdriver'
Selenium::WebDriver::Firefox::Binary.path='C:\Program Files\Mozilla Firefox\firefox.exe'
browser = Watir::Browser.new :ff
#blah blah more code
browser.close
end
end
If I run the Watir code from the command prompt using $ ruby filename.rb, I have no problems. For some reason, when I try to run it via the Rake command I get the above error. I'm struggling to find what's happening given that I see the code work okay alone.
I've tried adding require 'rubygems' but that doesn't work.
If you are on Linux then run:
sudo apt-get install nodejs
On Mac:
brew install node
I try to connect mysql with ruby, I follow this video
https://www.youtube.com/watch?v=GY7Ps8fqGdc
but on 23:30 in video, I got error with rake db:schema:dump,
I have no idea, this is my error:
irb(main):016:0> rake db:schema:dump
SyntaxError: (irb):16: syntax error, unexpected tLABEL
rake db:schema:dump
^
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
rake is a command-line tool. It is not supposed to be executed inside irb or the Rails console.
Try doing that from the command-line.
irb is for evaluating Ruby code only, which is a different thing than the command-line tools like rails and rake even if they are written in Ruby.
At the outset, get out of irb console.
rake is a build program, similar to make. Just go to your project directory on terminal and run your rake commands like:
~/apps/myproject$ rake db:schema:dump
I'm trying to debug rake task in rubymine. I created debug configuration for this task. Ruby SDK I chose project SDK. When I try to run this I got:
Gem::LoadError: You have already activated rake 10.2.2, but your Gemfile requires rake 10.1.1. Prepending `bundle exec` to your command may solve this.
/home/arkency/RubyProject/trainer/config/boot.rb:6:in `<top (required)>'
/home/arkency/RubyProject/trainer/config/application.rb:1:in `<top (required)>'
/home/arkency/RubyProject/trainer/Rakefile:5:in `<top (required)>'
/home/tomek/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/lib/ruby-debug-ide.rb:86:in `debug_load'
/home/tomek/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/lib/ruby-debug-ide.rb:86:in `debug_program'
/home/tomek/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/bin/rdebug-ide:110:in `<top (required)>'
When I run task from terminal all works fine. I don't know from where rubymine takes this rake gem. How to check it? How to change to use the proper Gem? Thanks for all answers.
Click Run => Debug => Edit Configurations, select Bundler tab and check the Run the script in context of the bundle
I tried running rake db:reset in my rails application after bundle install. The following message is displayed
rake aborted!
cannot load such file -- indirizzo
/home/xyz/Desktop/Signup4/app/models/concerns/address_validation.rb:2:in `<module:AddressValidation>'
/home/xyz/Desktop/Signup4/app/models/concerns/address_validation.rb:1:in `<top (required)>'
/home/xyz/Desktop/Signup4/app/models/location.rb:2:in `<class:Location>'
/home/xyz/Desktop/Signup4/app/models/location.rb:1:in `<top (required)>'
/home/xyz/Desktop/Signup4/db/seeds.rb:11:in `<top (required)>'
Tasks: TOP => db:setup => db:seed
(See full trace by running task with --trace)
bundle show Indirizzo displays
/usr/local/lib/ruby/gems/2.0.0/gems/Indirizzo-0.1.7
It seems to me the problem is in correct require.
According to readme https://github.com/daveworth/Indirizzo#usage it should be
require 'Indirizzo'
but the fact that it does not work (the same error).
It think it should be the same as in the internal lib https://github.com/daveworth/Indirizzo/blob/master/lib/indirizzo.rb
require 'indirizzo/address'
after this I manage to complete this example Indirizzo::Address.new("some address")
I have been using ruby on rails fine no problem, now suddenly every time I run rake db:create I get the following errors:
C:\>cd xampp
C:\xampp>cd htdocs
C:\xampp\htdocs>cd what
C:\xampp\htdocs\what>rake db:create
rake aborted!
undefined method `task' for #<What::Application:0x20eb1e0>
(See full trace by running task with --trace)
C:\xampp\htdocs\what>
Any help please???
Here is all my cmd
C:\xampp\htdocs\comeon>rake db:create --trace
rake aborted!
undefined method `task' for #<Comeon::Application:0x211fb30>
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:215:
in `initialize_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:
in `load_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:i
n `method_missing'
C:/xampp/htdocs/comeon/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `lo
ad'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `lo
ad_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:495:in `r
aw_load_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:78:in `bl
ock in load_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:77:in `lo
ad_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:61:in `bl
ock in run'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:59:in `ru
n'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/bin/rake:31:in `<top (required)>'
C:/Ruby192/bin/rake:19:in `load'
C:/Ruby192/bin/rake:19:in `<main>'
This will help you.
gem uninstall rake
gem install rake -v 0.8.7
If Still the problem exists, uninstall rake and install using
gem uninstall rake
gem install rake
for more info
Undefined method 'task' using Rake 0.9.0
I was having the same problem, found a post by Jim Weirich in git hub that solved my problem
https://github.com/jimweirich/rake/issues/33#issuecomment-1213705
Two issues here: (1) dimitko's issue is that the built in rake command is being mixed with the new gem's library files. Arranging your $PATH environment list so that the gem version of rake has precendence over the built-in version should fix that. If you are using bundler, you might also want to try 'bundle exec rake'.
The second issue (mjansen401 and r00k above) is that the new version of rake does not put its DSL commands (task, file, desc, import, etc) in the root of the Object namespace anymore (placing them in Object meant every object has a task command, not very nice . The DSL commands are available by mixing in the Rake::DSL module into any module needing the commands.
Until rails is updated to work with Rake 0.9.x, put the following in your project Rakefile before the call to Application.load_tasks:
class Rails::Application
include Rake::DSL if defined?(Rake::DSL)
end
Let me know if these work for you.
Hope it helps