AWS Elastic Beanstalk Error - Passenger - ruby-on-rails

I've tried various solutions that are intuitive and then have tried the solutions that have apparently helped others. I've spun up and terminated my Rails 4 app about 10 times. So...I thought I'd turn here to see if anyone knew an answer.
Here is the log file:
[ 2015-03-06 06:12:27.0070 2619/7fa0f6d60740 agents/Watchdog/Main.cpp:538 ]:
Options: { 'analytics_log_user' => 'webapp', 'cleanup_pidfiles' =>
'L3RtcC9wYXNzZW5nZX*********************yL3RlbXBfZGlyX3RvdWNoZXIucGlk',
'default_group' => 'webapp', 'default_python' => 'python', 'default_ruby' =>
'/opt/rubies/ruby-2.1.5/bin/ruby', 'default_user' => 'webapp', 'log_level' =>
'0', 'max_pool_size' => '6', 'passenger_root' => '/tmp/passenger-
standalone.1fcb7jr/locations.ini', 'passenger_version' => '4.0.53',
'pool_idle_time' => '300', 'prestart_urls' => 'aHR0cDovLzAuMC4wLjA6ODAA',
'temp_dir' => '/tmp', 'union_station_gateway_address' =>
'gateway.unionstationapp.com', 'union_station_gateway_port' => '443',
'user_switching' => 'false', 'web_server_passenger_version' => '4.0.53',
'web_server_pid' => '2618', 'web_server_type' => 'nginx',
'web_server_worker_gid' => '496', 'web_server_worker_uid' => '497' }
[ 2015-03-06 06:12:27.3877 2622/7fac802f6740 agents/HelperAgent/Main.cpp:650]:
PassengerHelperAgent online, listening at
unix:/tmp/passenger.1.0.2618/generation-0/request
[ 2015-03-06 06:12:28.2222 2630/7fe1e0b67740 agents/LoggingAgent/Main.cpp:321
]: PassengerLoggingAgent online, listening at
unix:/tmp/passenger.1.0.2618/generation-0/logging
[ 2015-03-06 06:12:28.2223 2619/7fa0f6d60740 agents/Watchdog/Main.cpp:728 ]:
All Phusion Passenger agents started!
2015/03/06 06:12:29 [error] 2638#0: *3 "/var/app/current/public/index.html" is
not found (2: No such file or directory), client: 127.0.0.1, server: _,
request: "HEAD / HTTP/1.1", host: "0.0.0.0"
2015/03/06 06:13:35 [error] 2638#0: *7 "/var/app/current/public/index.html" is
not found (2: No such file or directory), client: 172.3*.**.***, server: _,
request: "GET / HTTP/1.1", host: "****************-env.elasticbeanstalk.com"
I have gem 'passenger' in my gem file...I have tried in both development (because I've seen a number of errors with production and passenger) and production and I swear I have never had this kind of trouble uploading to elastic beanstalk. In fact this is a very stripped down app with only a static page and both devise for a user and devise for active admin. No errors or problem in either environment on my local machine.
I've never even realized I needed the index.html file...I always assumed that was only in php and other languages and that Rails took care of that for you with root. And like I said I've never seen this problem before. So to test that I put in an index.html file in the public folder and I could see that ahead of my root route on my local machine, but still no dice in AWS. I'd prefer to be able to drop this in and one of the other configs like just Puma. And I see a Puma and Nginx config available, but not in the GUI which is what I was planning to just "drop" this in and be done with it for the time being. I'm using a t2.small instance.
Any help or direction would be greatly appreciated. Thanks.
UPDATE: I've now tried this pushing through Git using Puma...etc. Trouble everywhere. It makes no sense. I even moved it to a "Hello World" app and still nothing. I'm about done with AWS. This is ridiculous. Nearly worse than an iOS release that has massive problems every year.

Ok. After today I have gotten this taken care of and hosted properly. In case this helps someone out...here were the key takeaways:
1) There is a Puma option if you are using CLI that is obvious. There is ALSO an option in the GUI, however it reads like a sentence instead of a logical select box. It DOES exist on the front page underneath the selection of the language to be installed. If you are getting a Passenger Error and expect to be using Puma, this is something you need to change.
2) I had installed a User model that contained an ActiveAdmin role as well. ActiveAdmin was pulling the gem from GitHub and I am using a machine with GitHub installed already. This really was the problem...switching to production and onto ElasticBeanstalk I forgot that git wasn't already installed. After going back through the errors many times, the common error was
# :github => 'activeadmin/activeadmin'+ '[' -d /vendor/cache ']'
+ bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
You need to install git to be able to use gems from git repositories.
[CMD-Startup/StartupStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
This is located in the eb-activity.log.
So, if this is similar to anything happening to you, you can do as follows:
1) start up your instance with the correct server.
2) if you get an error, look through that activity log mentioned above. (All the logs for that matter)
3) If the error fails similarly there is NO NEED to delete the instance. Leave it running.
4) SSH into the server instance that you just created. Run
sudo yum update
that is more than likely recommended. And then run
sudo yum install git
5) Upload the same exact file and name the version 0.1 and when it's through it should be green if this was your only error. Click the link and Voila.

For the git binary problem: It will fail again, if more instances are spinning up. You can avoid that by adding a config under $ROOT/.ebextensions which will be used for any new instance.
# Install git in order to be able to bundle gems from git
packages:
yum:
git: []

Related

How To Get The Value Of An Environment Variable In Elixir On Windows?

Windows 10
Elixir 1.3.1
Per the advice in this article, I've tried to modify my config files to use the "${ENV_VAR}" syntax. But then when I try to compile the code Elixir complains about the values of the configuration settings. So I tried the syntax directly in iex and it doesn't seem to work.
iex(1)> "${PATH}"
"${PATH}"
iex(2)> System.get_env("PATH")
"C:\\Program Files\\erl8.0\\erts-8.0\\bin;C: . . ." (rest omitted for brevity's sake)
I'd really like to use the "${ENV_VAR}" notation because it'd be nice to not have to hand-edit the sys.config file. Am I doing something wrong or is this just a Windows specific issue?
Here's part of my config file (even though, as I say, it seems I can reproduce the behavior in iex):
config :riismi, ecto_repos: [Riismi.Repo]
config :riismi, Riismi.Mailer,
adapter: Bamboo.SMTPAdapter,
server: "smtp.gmail.com",
port: 465,
username: "${RMI_MAIL_SERVERUSER}",
password: "${RMI_MAIL_SERVERPWD}",
tls: :if_available, # can be `:always` or `:never` or `:if_available`
ssl: true, # can be `true`
retries: 3
As I say, I realize this is likely to be a Windows issue--just wanted to insure that I'm not missing something otherwise.

Homebrew: Can't start elastic search

I'm in a big trouble, I can't start Elasticsearch and I need it for run my rails locally, please tell me what's going on. I installed Elasticsearch in the normal fashion then I did the following:
elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
But it shows the following error: [2015-11-01 20:36:50,574][INFO ][bootstrap] es.config is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed.
I tried several alternative ways of run it, like:
elasticsearch -f -D
But then I get the following error, and I can't find any useful for solve it, it seems to be related with file perms but not sure:
java.io.IOException: Resource not found: "org/joda/time/tz/data/ZoneInfoMap" ClassLoader: sun.misc.Launcher$AppClassLoader#33909752
at org.joda.time.tz.ZoneInfoProvider.openResource(ZoneInfoProvider.java:210)
at org.joda.time.tz.ZoneInfoProvider.<init>(ZoneInfoProvider.java:127)
at org.joda.time.tz.ZoneInfoProvider.<init>(ZoneInfoProvider.java:86)
at org.joda.time.DateTimeZone.getDefaultProvider(DateTimeZone.java:514)
at org.joda.time.DateTimeZone.getProvider(DateTimeZone.java:413)
at org.joda.time.DateTimeZone.forID(DateTimeZone.java:216)
at org.joda.time.DateTimeZone.getDefault(DateTimeZone.java:151)
at org.joda.time.chrono.ISOChronology.getInstance(ISOChronology.java:79)
at org.joda.time.DateTimeUtils.getChronology(DateTimeUtils.java:266)
at org.joda.time.format.DateTimeFormatter.selectChronology(DateTimeFormatter.java:968)
at org.joda.time.format.DateTimeFormatter.printTo(DateTimeFormatter.java:672)
at org.joda.time.format.DateTimeFormatter.printTo(DateTimeFormatter.java:560)
at org.joda.time.format.DateTimeFormatter.print(DateTimeFormatter.java:644)
at org.elasticsearch.Build.<clinit>(Build.java:51)
at org.elasticsearch.node.Node.<init>(Node.java:135)
at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
[2015-11-01 20:40:57,602][INFO ][node ] [Centurius] version[2.0.0], pid[22063], build[de54438/2015-10-22T08:09:48Z]
[2015-11-01 20:40:57,605][INFO ][node ] [Centurius] initializing ...
Exception in thread "main" java.lang.IllegalStateException: failed to load bundle [] due to jar hell
Likely root cause: java.security.AccessControlException: access denied ("java.io.FilePermission" "/usr/local/Cellar/elasticsearch/2.0.0/libexec/antlr-runtime-3.5.jar" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.util.zip.ZipFile.<init>(ZipFile.java:210)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:103)
at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:173)
at org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:340)
at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:113)
at org.elasticsearch.node.Node.<init>(Node.java:144)
at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
Thanks for your help.
There are some changes with libexec with Elasticsearch/homebrew installation and that is why it is failing to start. There is a PR #45644 currently being worked on. Till the PR gets accepted, you can use the same formula to fix the installation of Elasticsearch.
First uninstall the earlier/older version. Then edit the formula of Elasticsearch:
$ brew edit elasticsearch
And use the formula from the PR.
Then do brew install elasticsearch, it should work fine.
To start Elasticsearch, just do:
$ elasticsearch
config option is no longer valid. For custom config, use path.config:
$ elasticsearch --path.conf=/usr/local/opt/elasticsearch/config

Capistrano & X-Sendfile

I'm trying to make X-Sendfile work for serving my heavy attachments with capistrano. I found that X-Sendfile is not working with symlinks. How could I handle the files inside a folder symlinked by Capistrano so?
my web server is apache2 + passenger
in my production.rb:
config.action_dispatch.x_sendfile_header = "X-Sendfile"
in my controller action:
filename = File.join([Rails.root, "private/videos", #lesson.link_video1 + ".mp4"])
response.headers["X-Sendfile"]= filename
send_file filename, :disposition => :inline, :stream => true, :x_sendfile => true
render nothing: true
my filesystem structure (where a "->" stands for "symlink" and indentation means subfolder):
/var/www/myproject
releases/
....
current/ -> /var/www/myproject/releases/xxxxxxxxxxxx
app/
public/
private/
videos/ -> /home/ftp_user/videos
my apache config
XSendFile on
XSendFilePath / #also tried /home/ftp_user/videos
My application is able to serve small files, but with big ones it gives a NoMemoryError(failed to allocate memory)
I think it's not using x-sendfile, because the behavior is the same if I don't use it.
Here are the response headers of the file i'm trying to serve
Accept-Ranges:bytes
Cache-Control:private
Connection:Keep-Alive
Content-Disposition:inline
Content-Range:bytes 0-1265/980720989
Content-Transfer-Encoding:binary
Content-Type:video/mp4
Date:Sat, 01 Mar 2014 13:24:19 GMT
ETag:"70b7da582d090774f6e42d4e44ae3ba5"
Keep-Alive:timeout=5, max=97
Server:Apache/2.4.6 (Ubuntu)
Status:200 OK
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Powered-By:Phusion Passenger 4.0.37
X-Request-Id:22ff0a30-c2fa-43fe-87c6-b9a5e7da12f2
X-Runtime:0.008150
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block
I really don't know how to debug it, if it's a x-sendfile issue or if I'm trying to do something impossible for the symlinks problem
EDIT:
Following the suggested answer in the accepted one, it "magically" started working!
I created a capistrano task this way:
task :storage_links do
on roles(:web), in: :sequence, wait: 2 do
#creo i link simbolici alle risorse
within "/var/www/my_application/current/private" do
execute :ln, "-nFs", "/home/ftp_user/videos"
end
end
end
I didn't manage to run it after finalize_update, so i run it after the restart, by hand.
And i corrected my apache configuration in this way:
XSendFilePath /var/www/my_application
(before i was pointing x-sendfile to the ftp folder)
In my response headers also now X-Sendfile is not appearing, and i got a 206 - partial content, but everything seems to work and apache is serving files in the right way (also very heavy files).
I know this can be a security issue, but i will try to point it to the last release of my application cause pointing it to the current symlink is not working.
Maybe I found a solution. How did you make your symlinks?
maybe you did ln -s, and it's not enough
Here they suggest using ln -nFs, so he recognizes it's a directory that you are linking in

Ruby net-ssh wirth proxy command causes freeze

I would like to connect to a remote computer via another using ruby.
This scheme is the following :
Local -> proxy -> remote
I have this code which is doing the work for a direct access :
require 'net/ssh'
Net::SSH.start(remote_host, remote_user) do |ssh|
puts ssh.exec!'hostname'
end
However, when I try with the proxy, the command 'hostname' is executed and correct, but then the code freezes, same if I call ssh.close.
Here is the code :
require 'net/ssh'
require 'net/ssh/proxy/command'
proxy_cmd = Net::SSH::Proxy::Command.new('ssh proxy_user#proxy_host nc %h %p')
Net::SSH.start(remote_host, remote_user, :proxy => proxy) do |ssh|
puts ssh.exec!'hostname'
end
The loggin is done without password thanks to a rsa key. And the proxycommand is working (I was using it in bash before)
Would someone knows what I am doing wrong ?
Thank you very much for your interest,
EDIT : here is the last line in the logs, it blocks there :
I, [2013-10-16T23:01:19.304778 #3785] INFO -- net.ssh.connection.session[4555128]: closing remaining channels (0 open)
I've just bumped in the same issue - command line ssh was working and net/ssh was hanging on me when using proxycommand.
Debuging net/ssh brought me as far as: https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/transport/session.rb#L113 and the whole thing was hanging on the .close call of the socket.
I'm not sure what caused this, but adding timeout to nc command seems to have solved it:
ProxyCommand ssh proxy_server#proxy_server nc -q 1 %h %p

Sendmail working in Linux Terminal, not in Rails 3

I'm running Ubuntu 10.04 with Rails 3.2.2.
I just installed and configured sendmail. When mail is sent through terminal it worked perfectly.
But when i try to call it through Rails, no success.
Although it doesn't really looks like it's failing though. I get no errors, and see this in my console:
#<Mail::Message:40338240, Multipart: false, Headers: <From: alert#email.com>, <To: chris#email.com>, <Subject: Hi chris, a testmail too you!>, <Mime-Version: 1.0>, <Content-Type: text/html>, <importance: High>, <X-Priority: 1>>
I am in development have the following settings in my development.rb:
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i -t'
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
I have setup an actionmailer, with the corresponding alert_mail.html.erb:
class UserMailer < ActionMailer::Base
default from: "alert#email.com"
def alert_mail(site)
#site = site
#user = site.user
#url = "http://example.com/login"
mail(:to => #user.email_address, :subject => "Hi chris, a testmail too you!", :importance => "High", 'X-Priority' => '1')
end
end
And this is what I call:
UserMailer.alert_mail(site)
Could it be something with permissions?
Things i've tried
- Tried running in production mode
- chmod'd the sendmail executables to 777
- Tried removing the priority settings
- Running it with rails server instead of nginx
I hope someone can help me, thanks in advance!
(email.com is just a replacement, i use a valid domain)
EDIT:
sadiqxs answer does indeed solve the problem when I try to execute the mail function through rails console. But it still doesn't work when it is supposed to, through my browser. Strange thing is, this seems to be happening in nginx only. When I stop nginx, and start rails server, then it works. But when I when nginx is the server, it doesnt send any mail.
I think you need to call
UserMailer.alert_mail(site).deliver
sadiqxs solution is the part of the answer to my question. It fixes the problem that I was calling the function wrong. But it was still not sending email for me. After a while i manage to get it working.
One of the things I found out is that there was actually another mail log which I did oversee:
/var/log/mail.log.1
It showed me the following error:
sendmail[4453]: NOQUEUE: SYSERR(nobody): can not chdir(/var/spool/mqueue-client/): Permission denied
I used ls -ld /var/spool/mqueue-client/ to see that the directory is restricted by the smmsp group:
drwxrws--- 2 smmsp smmsp 4096 2013-01-12 17:51 /var/spool/mqueue-client/
So I added the nobody user (from the error SYSERR(nobody)) to the smmsp group:
usermod -a -G smmsp nobody
I tested again, and it doesn't work yet. After checking the log I got the same error. To be sure I rebooted my server and now the error message changed a little bit:
NOQUEUE: SYSERR(nobody): can not write to queue directory /var/spool/mqueue-client/ (RunAsGid=65534, required=115): Permission denied
After searching and trying useless stuff for a while i decide to change the primary group of nobody to 115 (smmsp) the /etc/psswd file and saw the following settings:
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
to
nobody:x:65534:115:nobody:/nonexistent:/bin/sh
This solved my problem and it's sending mails now. I understand that this is not the best solution, but I don't really know how else I would give nobody access, since it's requiring the specific GID. I hope someone else here does.

Resources