您能在弹性beanstalk环境中运行rails控制台或rake命令吗?

时间:2021-01-11 22:27:42

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 effectively empty. If I move up a directory, there is also a /home/webapp directory that i do not have access to.

我在AWS的弹性豆茎上建立了一个RoR环境。我能够ssh到我的EC2实例。我的主目录是/home/ec2-user,它实际上是空的。如果我向上移动一个目录,还有一个/home/webapp目录我无法访问。

Is there a way to run a rake command or rails console on my elastic beanstalk instance?

有办法在我的弹性beanstalk实例上运行rake命令或rails控制台吗?

If I type rails console I get Usage: rails new APP_PATH [options] If I type RAILS_ENV=production bundle exec rails console, I get "Could not locate Gemfile"

如果我输入rails控制台,我得到使用:rails新的APP_PATH[选项]如果我输入RAILS_ENV=product bundle exec rails控制台,我得到“无法定位Gemfile”

7 个解决方案

#1


51  

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

对于rails,跳转到/var/app/current,然后如@juanpastas所说,运行RAILS_ENV=生产包exec rails c。

#2


30  

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

不知道为什么,但是因为EBS把所有的东西都当作root用户来运行,所以对我来说是可行的:

sudo su
bundle exec rails c production

#3


14  

None of these solutions mentioned here worked for me, so I cooked up a little script that I put in script/aws-console.

这里提到的这些解决方案对我都不起作用,因此我编写了一个小脚本,并将其放在脚本/aws-console中。

You can run it from the /var/app/current directory as root:

您可以从/var/app/current目录作为root:

eb ssh
cd /var/app/current
sudo script/aws-console

My script can be found as a Gist here.

我的剧本可以在这里找到要点。

#4


8  

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

没有其他的答案对我有用,所以我去找了——这是我现在正在为我工作的一个弹性beanstalk 64位亚马逊linux 2016.03 V2.1.2 ruby 2.2 (puma)堆栈。

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>

#5


2  

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

我喜欢在我的rails应用程序的根上创建eb_console文件,然后创建chmod u+x。它包含以下:

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.

就像我运行heroku运行bundle exec rails c。

#6


0  

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

你必须找到你的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.

为此,我将查看web服务器配置中应该有一个配置,告诉您应用程序目录的位置。

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.

在Apache配置中搜索包含your_app_name的文件。

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

或者如果你使用nginx,用nginx替换上面的apache。

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

找到应用程序文件夹后,将cd放入其中并运行RAILS_ENV=生产bundle exec rails c。

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

确保您的应用程序配置为在Apache或nginx配置中运行。

#7


0  

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.

这些对我都不起作用,包括操作系统控制台脚本。最后,我在/var/app/current中创建了一个脚本目录,然后在这个目录中创建了一个rails文件作为另一个SO问题的概要。

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.

它工作。

#1


51  

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

对于rails,跳转到/var/app/current,然后如@juanpastas所说,运行RAILS_ENV=生产包exec rails c。

#2


30  

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

不知道为什么,但是因为EBS把所有的东西都当作root用户来运行,所以对我来说是可行的:

sudo su
bundle exec rails c production

#3


14  

None of these solutions mentioned here worked for me, so I cooked up a little script that I put in script/aws-console.

这里提到的这些解决方案对我都不起作用,因此我编写了一个小脚本,并将其放在脚本/aws-console中。

You can run it from the /var/app/current directory as root:

您可以从/var/app/current目录作为root:

eb ssh
cd /var/app/current
sudo script/aws-console

My script can be found as a Gist here.

我的剧本可以在这里找到要点。

#4


8  

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

没有其他的答案对我有用,所以我去找了——这是我现在正在为我工作的一个弹性beanstalk 64位亚马逊linux 2016.03 V2.1.2 ruby 2.2 (puma)堆栈。

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>

#5


2  

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

我喜欢在我的rails应用程序的根上创建eb_console文件,然后创建chmod u+x。它包含以下:

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.

就像我运行heroku运行bundle exec rails c。

#6


0  

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

你必须找到你的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.

为此,我将查看web服务器配置中应该有一个配置,告诉您应用程序目录的位置。

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.

在Apache配置中搜索包含your_app_name的文件。

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

或者如果你使用nginx,用nginx替换上面的apache。

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

找到应用程序文件夹后,将cd放入其中并运行RAILS_ENV=生产bundle exec rails c。

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

确保您的应用程序配置为在Apache或nginx配置中运行。

#7


0  

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.

这些对我都不起作用,包括操作系统控制台脚本。最后,我在/var/app/current中创建了一个脚本目录,然后在这个目录中创建了一个rails文件作为另一个SO问题的概要。

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.

它工作。