I have set up a RoR environement on AWS\' elastic beanstalk. I am able to ssh into my EC2 instance. My home directory is /home/ec2-user, which is effective
None of these were working for me, including the aws-console script. I finally ended up creating a script
directory in /var/app/current
and then creating a rails
file in that directory as outline by this answer on another SO question.
eb ssh myEnv
cd /var/app/current
sudo mkdir script
sudo vim script/rails
Add this to file and save:
echo #!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
Then make it executable and run it:
sudo chmod +x script/rails
sudo script/rails console
And it worked.
#!/bin/sh
shell_join () {
ruby -r shellwords -e 'puts Shellwords.join(ARGV)' "$@"
}
command_str () {
printf 'set -e; . /etc/profile.d/eb_envvars.sh; . /etc/profile.d/use-app-ruby.sh; set -x; exec %s\n' "$(shell_join "$@")"
}
exec sudo su webapp -c "$(command_str "$@")"
Put above file somewhere in your source code, deploy, eb ssh
into the eb instance, cd /var/app/current
, and then execute path/to/above/script bin/rails whatever argumeents you usually use
.
Reason why I have written above script is:
sudo
, it drops some environment variables which might actually be needed for your rails app; so manually load the profiles which the Elastic Beanstalk platform provides.webapp
, a non-login-able user, so it would be wise to run your command in this user.For rails, jump to /var/app/current
then as @juanpastas said, run RAILS_ENV=production bundle exec rails c
None of these solutions mentioned here worked for me, so I cooked up a little script that I put in script/aws-console.
You can run it from the /var/app/current directory as root:
eb ssh
cd /var/app/current
sudo script/aws-console
My script can be found as a Gist here.
Don't know why, but since EBS runs everything as root, this worked for me:
sudo su
bundle exec rails c production