Error while installing ruby on rails on server - ruby-on-rails

After installing rvm when i run this
source $HOME/rvm/scripts/rvm
i get error
-bash: /root/rvm/scripts/rvm: No such file or directory

reference: Problem deploying Ruby+RVM and daemontools
I found the answer but looking at the rvmsudo script installed with
rvm, here is a working run script:
#!/bin/sh
# redirect stderr to stdout
exec 2>&1
cd /app
# load rvm
. /usr/local/rvm/scripts/rvm
# select ruby version for this application
rvm use 1.9.1
# # depending on your configuration you may need to provide the absolute path to rvm, like that:
# /usr/local/bin/rvm use 1.9.1
# build the exec command line preserving the rvm environment
command="exec sudo -u app_user /usr/bin/env PATH='$PATH'"
[[ -n "${GEM_HOME:-}" ]] && command="${command} GEM_HOME='$GEM_HOME' "
[[ -n "${GEM_PATH:-}" ]] && command="${command} GEM_PATH='$GEM_PATH' "
# this is where your real command line goes
command="${command} ruby main.rb"
# run the application
eval "${command}"

Try source ~/.rvm/scripts/rvm. Exit out of your current shell and then try again it should work.

Related

Bundler Trying To Run Under Wrong Version of Ruby

I have a rails site, which I deploy via ssh using a git post-receive hook. When I ssh into the server and run bundle install it runs correctly under the specified ruby version of 2.2.2. However, when I push to the server from my local machine and it hits the 'bundle install command', I get the following:
hooks/post-receive: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
I can't find for the life of me why it is pointing to ruby1.9.1. This directory does not exist. I do see a directory for ruby2.3 in that directory, but not ruby2.2.2 which is the correct directory. Something is quite fouled up, but I can't figure how to fix it. Anyone seen anything like this?
UPDATE: Here is my post-receive hook, as per the request below...
#!/bin/bash
GIT_DIR=/home/deploy/www_production
WORK_TREE=/home/deploy/www
export MGOTS_DATABASE_USER='user'
export MGOTS_DATABASE_PASSWORD='pass'
export RAILS_ENV="production"
. ~/.bash_profile
while read oldrev newrev ref
do
if [[ $ref = refs/heads/master ]];
then
echo "Master ref received. Deploying master branch to production..."
mkdir -p $WORK_TREE
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log
# start deploy tasks
cd $WORK_TREE
bundle install
rake db:create
rake db:migrate
rake assets:precompile
rake requests:cleanup
sudo restart puma-manager
sudo service nginx restart
# end deploy tasks
echo "Git hooks deploy complete"
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
UPDATE: For the sake of clarity, as the answer points to the correct place to find the answer, but doesn't state it exactly, I am posting my updated hook file here. You can see the difference between this one and the one above, and that is what solved the problem. Please note that the path to the rvm directory can be found by typing the command: which rvm - that's the one you want to point to.
#!/bin/bash
GIT_DIR=/home/deploy/www_production
WORK_TREE=/home/deploy/www
export MGOTS_DATABASE_USER='user'
export MGOTS_DATABASE_PASSWORD='pass'
export RAILS_ENV="production"
export RUBYGEMS_GEMDEPS="/home/deploy/.rvm/ruby-2.2.2#www/gems"
. ~/.bash_profile
[[ -s "/usr/share/rvm/bin/rvm" ]] && source "/usr/share/rvm/bin/rvm"
while read oldrev newrev ref
do
if [[ $ref = refs/heads/master ]];
then
echo "Master ref received. Deploying master branch to production..."
mkdir -p $WORK_TREE
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log
# start deploy tasks
cd $WORK_TREE
bundle install
rake db:create
rake db:migrate
rake assets:precompile
rake requests:cleanup
sudo restart puma-manager
sudo service nginx restart
# end deploy tasks
echo "Git hooks deploy complete"
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
You need to load RVM functions to the shell script. link
Or just switch to Rbenv :)
First, set your default ruby to use the version 2.2.2
Are you using RVM? For RVM its: rvm use --default 2.2.2

Add local binstubs to rbenv (getting command not found)

If you have simple shell command binstubs in the local bin directory of a Rails project (e.g. not generated by or running a gem), rbenv seems to have trouble executing them. For example, #tpope's heroku binstubs generate a binstub named production in the local bin directory:
#!/bin/sh
HEROKU_APP=myapp-production HKAPP=myapp-production exec "${HEROKU_COMMAND:-heroku}" "$#"
After an rbenv rehash, the production command shows up in the ~/.rbenv/shims directory looking something like this:
#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x
program="${0##*/}"
if [ "$program" = "ruby" ]; then
for arg; do
case "$arg" in
-e* | -- ) break ;;
*/* )
if [ -f "$arg" ]; then
export RBENV_DIR="${arg%/*}"
break
fi
;;
esac
done
fi
export RBENV_ROOT="/Users/Username/.rbenv"
exec "/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv" exec "$program" "$#"
So executing which production gives you:
/Users/Username/.rbenv/shims/production
But executing rbenv which production (or trying to run the command) gives you:
rbenv: production: command not found
I'm new to rbenv so maybe I missed a config step?
Apparently project-specific binstubs in Rails projects should be kept outside of the local bin/ directory since those are primarily for application scripts. So one approach (i.e. that used by the rbenv-binstubs plugin) is to keep local binstubs separate and override rbenv shims with that local binstub directory (e.g. .bundle/bin). So by using the plugin you might see this result from which production:
/Users/Username/.rbenv/shims/production
But if you move the production binstub to .bundle/bin, then rbenv which production should yield:
{PROJECT_ROOT}/.bundle/bin/production

bundle not found when running services using upstart/foreman

I'm setting up a staging environment for a Rails 4 app on Ubuntu 12.04.
I use:
- rbenv for managing rubies
- capistrano for deployemnt
- foreman for managing services
In particular, I want to run que as a service. My Procfile looks like
que: bundle exec rake que:work
I have exported the Procfile for upstart successfully. My sapp-que-1.conf looks like
start on starting ft-id-que
stop on stopping ft-id-que
respawn
exec su - deployer -c 'cd /home/deployer/apps/sapp/releases/20140307080502; export PORT=5000; bundle exec rake que:work >> /home/deployer/apps/sapp/current/log/que-1.log 2>&1'
When I try to start it (sudo start sapp) I get the following error:
-su: bundle: command not found
However if I cd into /home/deployer/apps/sapp/releases/20140307080502 and I manually run bundle exec rake que:work the rake is executed.
Am I missing anything here?
Thanks.
Could you have .bash_profile ?
The su does not read .bashrc.
[SOLVED] Special user, .bashrc not being executed upon login
I create .bash_profile with
# Load the default .profile
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile"
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

.rvmrc syntax error

I am trying to work with a web app made by someone else. I cloned that repo and when I cd'ed into it, the .rvmrc executed. But I am getting the following error in it:
: command not found
: command not found
: command not found
: command not found
-bash: /home/sleepingdragon/Desktop/sharedcab/main-apps/ytaxi-apps/yTaxi/.rvmrc: line 22: syntax error in conditional expression
-bash: /home/sleepingdragon/Desktop/sharedcab/main-apps/ytaxi-apps/yTaxi/.rvmrc:'line 23: syntax error near `]]
-bash: /home/sleepingdragon/Desktop/sharedcab/main-apps/ytaxi-apps/yTaxi/.rvmrc:'line 23: ` && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
The .rvmrc file is this:
#!/usr/bin/env bash
# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory
# First we specify our desired <ruby>[#<gemset>], the #gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.9.3" > .rvmrc
environment_id="ruby-1.9.3-p194#ytaxi"
# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.14.2 (stable)" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
# return 1
# }
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
if [[ $- == *i* ]] # check for interactive shells
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
fi
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create use "$environment_id" || {
echo "Failed to create RVM environment '${environment_id}'."
return 1
}
fi
# If you use bundler, this might be useful to you:
# if [[ -s Gemfile ]] && {
# ! builtin command -v bundle >/dev/null ||
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
# }
# then
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
# gem install bundler
# fi
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
# then
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
# fi
I have not worked with .rvmrc before and am a Rails noob. Could you help me find the error?
Just create .ruby-version file containing
ruby-1.9.3-p194#ytaxi
and delete the .rvmrc file.
You are using minimal version of .rvmrc which also is buggy, you could either fix it:
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" &&
-s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
and you can switch to the new .ruby-version file:
rvm get stable
rvm rvmrc to ruby-version

How do I use bundle exec in Aptana Studio 3.0.9 to run the debugger?

Aptana seems to start in the sh shell. So I'm trying to switch to zsh, and execute commands to start a rails app.
I've changed my debug executable so that it runs a unix executable with the following contents:
#!/usr/bin/env ruby
exec("zsh | (echo $SHELL && [[ -s '$HOME/.rvm/scripts/rvm' ]] && source '$HOME/.rvm/scripts/rvm' && rvm use 1.8.7#tinderbox && (bundle exec script/server -p3001 &))")
So, when I click my debug executable from the debug menu on the toolbar, the debug perspective appears, and it shows that
myApp [Ruby Application]
Ruby
/usr/bin/ruby
is running and hasn't been terminated.
but when I go to my browser and type in 0.0.0.0:3001, I get "Oops! Google Chrome could not connect to localhost:3001" - which means that the server sin't running.
I have the output of the executable set to a file on my desktop here is what happens every run:
Fast Debugger (ruby-debug-ide 0.4.16, ruby-debug-base 0.10.4) listens on 127.0.0.1:55306
/bin/zsh
Note: I get the same results with bash as with zsh
What is going on? and how do I get my command to work?
type
zsh -l
and in new zsh shell:
rvm 1.8.7 do bundle exec script/server -p3001
or with rvm wrapper:
generate wrapper for bundle:
rvm wrapper 1.8.7 run bundle
it will generate run_bundle, find it:
which run_bundle
and use it in aptana:
/path/to/run_bundle exec script/server -p3001

Resources