AWS elastic beanstalk is not getting the environment variables - ruby-on-rails

I'm trying to run a Rails 6 app on AWS Elastic Beanstalk, but I get from puma log the following (repeats every few seconds)
[21776] + Gemfile in context: /var/app/current/Gemfile
[21776] Early termination of worker
The version numbers:
Rails 6.0.3.3
puma 4.3.5
ElasticBeanstalk Ruby 2.7 running on 64bit Amazon Linux 2/3.1.1
ruby 2.7.1p83
The server is unresponsive from outside the instance, and there's nothing on log/production.log.
Running on a dev machine on production mode there's no errors, and the database is reachable (no migration failure).
Running on the AWS instance the command bundle exec puma -p 3000 -e production I get
Puma starting in single mode...
Version 4.3.5 (ruby 2.7.1-p83), codename: Mysterious Traveller
Min threads: 5, max threads: 5
Environment: production
Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
so there's no obvious error that may cause the worker to halt.
How can I find out what's causing the workers to fail?
Edit 1:
I ran Rails console on the instance and found that the environment variables are missing - e.g. the production database user/pass/host. Once I hardcoded them I could connect to the database.
I suspect the absence of other environment variables is making the app crash.

A user on AWS forum had the answer.
Setting in my Gemfile
gem "nio4r", "= 2.5.2"
fixed the issue.

Related

Ruby rails, local server dont start with rails s

im working on linux, on a project with ruby on rails.
I have a probléme when i use rails s.
Normaly when i do rails s i can see that :
Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.5 (ruby 2.6.3-p62), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
and i can see my project on localhost 3000
But now, on my current project, its juste do :
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Nothing more, no error message and i just cant acces to my project on localhost3000.
I tryed to specify a port with rails s -p 3000 or a PID with rails -P ... but its didnt changed nothing
i tryed rake rails:update:bin but it didnt changed anything also
Do you have any idea of what i could do for solve my problem and work agan localy on my projet?
Thank's
I guess your errors (std::err) are hidden from console.
You must be having this error
=> A server is already running. Check /YourProjectPath/tmp/pids/server.pid.
go to tmp/pids/server.pid, You will find a server ID there. Run the following command on your terminal with your server ID.
i.e:
$ kill 13455
//where 13455 is server ID for my project.
if it doest not work. Restart your PC.
You can use webrick server instead of puma server using rails s webrick

Rails SSL while running only Puma on EC2 AWS instance

Specs: Rails 4.2.4, Ruby 2.1.9, running puma, EC2 instance in production mode
I have an SSL certificate that I want to install on my server but using techniques like this one yields no results
rails s puma -b 'ssl://0.0.0.0:9292?key=path_to_key.key&cert=path_to_cert.crt&verify_mode=none&ca=path_to_root_bundle.crt'
How to configure Rails with Puma to use SSL?
also
RAILS_ENV=production rvmsudo -E rails s puma -b "ssl://0.0.0.0:9292?key=${KEY_PATH}&cert=${CERT_PATH}&verify_mode=peer&ca=${CERT_BUNDLE_PATH}" -p 80
Instead of a functioning server I get
Puma starting in single mode...
* Version 3.2.0 (ruby 2.1.9-p490), codename: Spring Is A Heliocentric Viewpoint
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://ssl://0.0.0.0:9292?key=~/evslideshow.key&cert=~/e3b162f57ea48f91.crt&verify_mode=peer&ca=~/gd_bundle-g2-g1.crt:80
Exiting
> /home/ec2-user/.rvm/gems/ruby-2.1.9#slideshow/gems/puma-3.2.0/lib/puma/binder.rb:240:in
`initialize': getaddrinfo: Name or service not known (SocketError)
Now my mind is playing with different options. Am I just missing some fundamental aspect of using puma here? The puma documentation is very scared which is why I'm asking here. Or I could use Nginx because it seems like there is alot of documentation on the internets on setting that up with SSL certificate.
If there is a simpler fix for puma then I will just use that.
Found the solution by reading through some of the issue pages on puma's Github page. Apparently we must call puma directly, and not through rails server, despite what was said here in this old stackoverflow answer
The working code is
RAILS_ENV=production rvmsudo -E puma -d -b "ssl://0.0.0.0:443?key=${KEY_PATH}&
cert=${CERT_PATH}&verify_mode=peer&ca=${CERT_BUNDLE_PATH}" -p 80
Make sure to turn on config.force_ssl in your production config file as well.

How to configure rails with puma on AWS elastic beanstalk app?

I have an EBS app using Ruby and Puma, in my rails app, I have puma.rb in /config/puma.rb as:
workers 2
threads 1, 6
app_dir = File.expand_path("../..", __FILE__)
# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env
activate_control_app
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
and I have puma gem listed in Gemfile and installed
when I deploy to elastic beanstalk app, I get a successful deployment, and the app state is green, however, when I visit the app link, I get error This site can’t be reached
I tried to ssh into the ec2 instance, puma command will get:
$ puma
Puma starting in single mode...
* Version 2.16.0 (ruby 2.5.1-p57), codename: Midwinter Nights Trance
* Min threads: 0, max threads: 16
* Environment: production
ERROR: No application configured, nothing to run
so, what do I miss?

Running Rails Console Gets Killed

When i run on my production servers the command:
bundle exec rails c production
After few seconds i get "Killed", the server has 32GB RAM and have no lack of memory.
I use Ruby 2.1.6 with Rails 4.2.9 On CentOS 6.5.
I tried add SWAP file it doesn't worked.

Deploying Ruby on Rails app on Nginx Puma localmachine

Hi I am trying to deploy RoR app using puma as application server and Nginx. Iam following tutoril available here:
http://codeonhill.com/rails-capistrano-puma-nginx-on-vps/
Sorry Being a newbie in deployment, I want to ask whether we can deploy Rails app using Nginx as reverse proxy on local machine?
Secondly after wasting an entire day i could able to deploy it sucessfully
user#username-VirtualBox:~/Rails/rails-nginx-passenger-ubuntu/testapp$ bundle exec puma -b unix://tmp/testapp.sock
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander
* Min threads: 0, max threads: 16
* Environment: development
* Listening on unix://tmp/testapp.sock
* Starting control server on unix:///tmp/puma-status-1490292608378-29275
Use Ctrl-C to stop
And when i am trying to access this url iam getting google search result. How to access my application over there?

Resources