Can you run a rails console or rake command in the elastic beanstalk environment?

主宰稳场 提交于 2019-11-29 20:45:58

For rails, jump to /var/app/current then as @juanpastas said, run RAILS_ENV=production bundle exec rails c

Don't know why, but since EBS runs everything as root, this worked for me:

sudo su
bundle exec rails c production

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.

None of the other answers worked for me so I went looking - this is working for me now on an elastic beanstalk 64bit amazon linux 2016.03 V2.1.2 ruby 2.2 (puma) stack

cd /var/app/current
sudo su
rake rails:update:bin
bundle exec rails console

that returns me the expected console

Loading production environment (Rails 4.2.6)
irb(main):001:0>

I like to create an eb_console file at the root of my rails app, then chmod u+x it. It contains the following:

ssh -t ec2-user@YOUR_EC2_STATION.compute.amazonaws.com  'cd /var/app/current && bin/rails c'

This way, I just have to run:

./eb_console

like I would have run heroku run bundle exec rails c.

jangosteve

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.

You have to find the folder with your Gemfile :p.

To do that, I would take a look in you web server config there should be a config that tells you where your app directory is.

Maybe you know where your app is.

But in case you don't know, I would give a try to:

grep -i your_app_name /etc/apache/*
grep -i your_app_name /etc/apache/sites-enabled/*

To search files containing your_app_name in Apache config.

Or if you are using nginx, replace apache above by nginx.

after you find application folder, cd into it and run RAILS_ENV=production bundle exec rails c.

Making sure that your application is configured to run in production in Apache or nginx configuration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!