How to create an RVM environment on a server through net-ssh? - rvm

I have a script which is installing Ruby/RVM (and more) on my server to get an environment ready to deploy a Rails project. This script is in ruby and use the net-ssh lib to do the job.
After having installed RVM, Ruby, I would like to create the project Gemset:
connection do |conn|
logger("Create RVM environment #{ruby_version}##{project_name}")
conn.exec!("#{rvmsudo_path} #{rvm_path} gemset create #{project_name}")
end
I get my gemset created under, all good:
/usr/local/rvm/gems/ruby-1.9.3-p286#my_project_name
Here is my Capistrano setting for rvm/ruby:
set :rvm_type, :system
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
When I'm trying to deploy using capistrano, I get:
/usr/local/rvm/environments/ruby-1.9.3-p286#my_project_name: Permission denied
The environment file 'ruby-1.9.3-p286#my_project_name' is actually missing in that folder. I need to log into the server and navigate to my project so the .rvmrc file to trigger the creation of the environment (rvm --create my_project_name). I would like to avoid this last step. Do you know how to trigger the creation of this environment? (I though it would create it when I have created the Gemset)

RVM has support for installing itself via capistrano, to install rubies and to create gemsets, you should make use of it:
https://rvm.io/integration/capistrano/#install_rvm
https://rvm.io/integration/capistrano/#install_ruby

Basically the RVM environment need to be loaded to be able to script it remotely.
https://rvm.io/workflow/scripting/
You can run the following command with net-ssh to do so:
conn.exec!("source "/usr/local/rvm/scripts/rvm; rvm --create ruby-1.9.3-p286#my_project_name")
It will create your environment and associated gemset.

Related

Get error in Lumen database migration after delete migration file manually

Below is the step that I followed.
php artisan migrate:install
php artisan make:migration create_categories_table --create=categories
So it's create migration table in database.
it's create 2016_11_24_054214_create_categories_table.php file in database/migrations folder with some basic stuff. I have added my columns information and run next command php artisan migrate so my table is created successfully.
Now I have deleted 2016_11_24_054214_create_categories_table.php file manually and delete categories table from database then I tried to create same categories table using same last command php artisan make:migration create_categories_table --create=categories but it's give me a below error.
[ErrorException]
include(/var/www/news_reporting/vendor/composer/../../database/migrations/2016_11_24_054214_create_categories_table.php): failed to open stream: No such file or directory
I googled and found one solution that run php composer dump-autoload command but this command give me below error.
Could not open input file: composer
I am using linux.
Could not open input file: composer
Please make sure that composer is installed in your system.
To check just go to terminal and write command composer if it is installed then you will see some stuff else you will get composer not found error
If above is a issue then you need to install composer in your system user this link for installing reference.
Or you might need to run php artisan migrate command for migrating migrations.
you don't need to precede composer with PHP command, try it this way:
composer dump-autoload
and that should solve your migration problem.

How do I ensure my jruby command line options are used when running "rails", "rake", "rspec" etc?

I currently run my Rails app using:
jruby --1.9 -J-XX:+CMSClassUnloadingEnabled -J-XX:+UseConcMarkSweepGC -J-XX:MaxPermSize=256m -S rails server
This is getting pretty old now. How can I set my Rails project up so that just running
rails server
has the same effect?
(Note: bash aliases and the like are not what I'm looking for here. I want to make the project work right, not fix my local settings)
When using RVM and a project .rvmrc, the canonical way is to set PROJECT_JRUBY_OPTS in the project .rvmrc. A bug prevented this from working for me, so use rvm head.
If not using rvm then use JRUBY_OPTS, which is the built-in way of doing it that JRuby checks (in fact, the PROJECT_JRUBY_OPTS thing ends up being converted to JRUBY_OPTS by rvm).

Rake tasks from cron - uninitialized constant YAML::ENGINE

I am getting uninitialized constant YAML::ENGINE when running a rake task from cron since I upgraded my server to ruby 1.9.2. I had the same error with the app but putting ...
require 'yaml'
YAML::ENGINE.yamler= 'syck'
in the boot.rb file fixed it. If I run the task directly from the command line on my Ubuntu server it works fine, the server uses RVM.
However running a task from cron doesn't seem to pickup this fix, I have tried this ...
task :twitter, :needs => :environment do
require 'yaml'
YAML::ENGINE.yamler= 'syck'
#tweets = Property.updatetwitter
end
to no avail.
Are you sure you're running it under Ruby 1.9.2? Because while YAML::ENGINE exists in 1.9.2, it's not in 1.8.7. Check your Ruby version.
UPDATE
How to tell which Ruby version program is using from within the program:
puts `ruby -v`
Lame way how to enforce cron task to run under certain Ruby version (if server uses RVM):
rvm use 1.8.7; ...

Register a script to use with the rails command, like `rails mycommand`

The rails command-line command provides a couple of commands, like rails generate, rails console etc. Now I'd like write a gem which registers my own command for use with rails mycommand.
Is this possible?
If so, any guides on how to do that?
NB: This is for rails 3+
regards, apeiros
Haven't done it, but here are some leads. In your Rails app, the script directory holds a file called 'rails' that has this line
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
It then requires this Rails file: https://github.com/rails/rails/blob/master/railties/lib/rails/commands.rb

setting production environment in rails 3.0

How is the environment set in Rails 3.0?
In Rails 2.x, environment.rb contained a line setting RAILS_ENV to production. It was commented out in the generated file. To force a production environment, uncomment that line.
Rails 3.0 contains no such line in environment.rb, and RAILS_ENV is deprecated. Is there something missing, or is the environment set when the server is started (eg "start Mongrel_rails -e production ..."
I'm trying out Rails 3.0 on my deployment host and getting some odd behavior. Specifically, it seems to be trying to load the :development object from database.yml, and it seems to be ignoring the :groups => :development option in the gemfile. Consequently the app is trying to use Sqlite3 on the deployment server where it is not available.
The replacement is Rails.env
I set the environment in my server config.. thin.yml, mongrel_cluster.yml, or whatever server I am using.
When you are using Cap, how do you call "bundle install"? You should be using the --deployment flag when deploying to prod. It would be helpful to see your deploy.rb file.