500 Internal Server Error with Rails Production - ruby-on-rails

I recently uploaded some new files to my production server (and overriding the old ones) and am now getting 500 Internal Server Error. The server is running phusion passenger (even though I am not getting that error message anymore) and in my local test environment everything seems to be working fine.
Here is the site: http://www.pandonews.com/
When I looked in my apache log i see this error:
[ pid=3106 thr=140057117177664 file=ext/apache2/Hooks.cpp:884 time=2013-09-01 17:37:24.84 ]: Unexpected error in mod_passenger: Cannot spawn application '/var/www/feedme': The spawn server died unexpectedly, and restarting it failed.
Backtrace:
in 'virtual Passenger::SessionPtr Passenger::ApplicationPool::Client::get(const Passenger::PoolOptions&)' (Client.h:742)
in 'Passenger::SessionPtr Hooks::getSession(const Passenger::PoolOptions&)' (Hooks.cpp:312)
in 'int Hooks::handleRequest(request_rec*)' (Hooks.cpp:585)
I have no idea what the problem is. It has been running fine up until now. I don't really know where to start in order to fix this. I tried running gem passenger install again but nothing happened.
Recent activities:
Installed pg gem (but removed it from gem file after deciding to stay with sqlite3 for now) the yml file should be ok...
Tried running bundle update on server and locally but it keeps hanging
Changed some javascript and css files...
Tried resetting the server with RAILS_ENV=production rake:db reset - no change!
EDIT:
when running rails s production i get the following error:
/home/otto/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- rack/handler/production (LoadError)
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `block in require'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `require'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.4.5/lib/rack/handler.rb:63:in `try_require'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.4.5/lib/rack/handler.rb:16:in `get'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.4.5/lib/rack/server.rb:272:in `server'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.7/lib/rails/commands/server.rb:59:in `start'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.7/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.7/lib/rails/commands.rb:50:in `tap'
from /home/otto/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.7/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
EDIT2:
$ passenger-status
ERROR: Phusion Passenger doesn't seem to be running.
EDIT3:
Seems like it is running, still internal server error:
passenger start -a 0.0.0.0 -p 3000 -d -e production
=============== Phusion Passenger Standalone web server started ===============
PID file: /var/www/feedme/tmp/pids/passenger.3000.pid
Log file: /var/www/feedme/log/passenger.3000.log
Environment: production
Accessible via: http://0.0.0.0:3000/
Serving in the background as a daemon.
===============================================================================
otto#scraper:/var/www/feedme$ passenger status
Phusion Passenger Standalone is running on PID 18788, according to PID file /var/www/feedme/tmp/pids/passenger.3000.pid
otto#scraper:/var/www/feedme$

Did the following:
gem install passenger (no sudo or anything)
Find root: passenger-config –root
Give chmod to all from root until username folder: sudo chmod -R 777 /home/username/.rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.14 to every folder until /home/username/
passenger-install-apache2-module (without anything)
Take the code you are given paste it inside: /etc/apache2/httpd.conf
sudo service apache2 restart

Related

Passenger cannot load rbenv managed versions

A server has two users. deploy has sudo privileges, guest does not.
guest has an application that is migrating ruby versions (from 2.3.4 to 2.4.5).
Initially, after guest installs version 2.4.5 passenger cannot start because it does not find this version of ruby. deploy had to install it. However, hte next phase of starting up the server fails to load the application, while at the same time confirming that it is seeking the version of ruby within the deploy user's directories
Error: The application encountered the following error: cannot load such file -- bundler/setup (LoadError)
/home/deploy/.rbenv/versions/2.4.5/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/deploy/.rbenv/versions/2.4.5/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:363:in `activate_gem'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:221:in `block in run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:527:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:220:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-loader.rb:86:in `load_app'
/usr/share/passenger/helper-scripts/rack-loader.rb:116:in `block in <module:App>'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:380:in `run_block_and_record_step_progress'
/usr/share/passenger/helper-scripts/rack-loader.rb:115:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-loader.rb:28:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-loader.rb:27:in `<main>'
passenger-config --ruby-command seems to be looking for the proper directory,
passenger-config was invoked through the following Ruby interpreter:
Command: /home/guest/.rbenv/versions/2.4.5/bin/ruby
Version: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
However,
rbenv exec gem environment gemdir
returns
/home/guest/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0
How can this be fixed?
The issue here relates to different users and ruby versions invoked.
passenger-config --ruby-command
returns the interesting passage, in this case:
To use in Nginx : passenger_ruby /home/guest/.rbenv/versions/2.4.5/bin/ruby
while the nginx/sites-enabled/relevant_application file does not need to have that invoked for a single user, this command becomes necessary with multiple users. Then restart nginx!

How to set puma to start on server start/reboot with capistrano?

I was going through puma upstart script and I tried to set it up on my server. But, after some trial and error I realized that I shouldn't be doing this manually and my deployment script i.e. capistrano should be doing this for me.
I google this but I could not much other than 2 lines on capistrano-puma:
For Jungle tasks (beta), these options exist:
set :puma_jungle_conf, '/etc/puma.conf'
set :puma_run_path, '/usr/local/bin/run-puma'
I am not sure how to use this and make capistrano do this rather than me manually doing it.
Work done so far:
I followed this blog- Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma and it works like a charm, except that I have to remember to run cap production puma:restart if I restart the server (or the puma process dies and I get cloudwatch alarms).
Following the official docs, I made a config file /etc/puma.conf:
/home/deploy/apps/<app_name>/current
but it is unable to find puma.rb- Naturally, as puma.rb is in
<app_name>/shared/puma.rb
and not in
<app_name>/current/config/puma.rb
The actual error I get in the logs:
/home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/dsl.rb:26:in `read': No such file or directory # rb_sysopen - config/puma.rb (Errno::ENOENT)
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/dsl.rb:26:in `_load_from'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/dsl.rb:9:in `load'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/configuration.rb:204:in `block in load'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/configuration.rb:201:in `each'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/configuration.rb:201:in `load'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/launcher.rb:62:in `initialize'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/cli.rb:65:in `new'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/cli.rb:65:in `initialize'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/bin/puma:8:in `new'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/gems/puma-3.4.0/bin/puma:8:in `<top (required)>'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/bin/puma:23:in `load'
from /home/deploy/apps/voggle/shared/bundle/ruby/2.2.0/bin/puma:23:in `<main>'

Error while running unicorn for Ruby on Rails

I am trying to run a Ruby on Rails app with nginx and unicorn. After setting up the unicorn configuration file 'unicorn.rb' when I try and execute this command
bundle exec unicorn -c config/unicorn.rb -D
It throws the following error:
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/lib/unicorn/configurator.rb:537:in `working_directory': config_file=config/unicorn.rb would not be accessible in working_directory=/home/vagrant/home (ArgumentError)
from config/unicorn.rb:3:in `reload'
from /home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/lib/unicorn/configurator.rb:72:in `instance_eval'
from /home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/lib/unicorn/configurator.rb:72:in `reload'
from /home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/lib/unicorn/configurator.rb:65:in `initialize'
from /home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/lib/unicorn/http_server.rb:76:in `new'
from /home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/lib/unicorn/http_server.rb:76:in `initialize'
from /home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/bin/unicorn:126:in `new'
from /home/vagrant/.rvm/gems/ruby-2.2.1/gems/unicorn-5.0.0/bin/unicorn:126:in `<top (required)>'
from /home/vagrant/.rvm/gems/ruby-2.2.1/bin/unicorn:23:in `load'
from /home/vagrant/.rvm/gems/ruby-2.2.1/bin/unicorn:23:in `<main>'
from /home/vagrant/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /home/vagrant/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
master failed to start, check stderr log for details
I am running inside an ubuntu-vagrant setup and my app is in the following directory:
/home/vagrant/home/my-app
And the configuration file(unicorn.rb) is in the following directory:
/home/vagrant/home/my-app/config
And the file(unicorn.rb) contains the following configurations:
working_directory "/home/vagrant/home/"
pid "/home/vagrant/home/temp/pids/unicorn.pid"
stderr_path "/home/vagrant/home/log/unicorn.log"
stdout_path "/home/vagrant/home/log/unicorn.log"
listen "/tmp/unicorn.expertiza.sock"
worker_processes 2
timeout 30
I dont understand where I am going wrong. Even the error statement doesnt make much sense. Can someone provide some assistance.

Rails-tutorial Chapter 1: rails server isn't working on Cloud9

https://www.railstutorial.org/book/beginning#sec-rails_server
I have reached this step, and I'm using the cloud9 environment. When I run the server as per Listing 1.7 on that tutorial, however, I get this error:
myname#rails-tutorial:~/workspace/hello_app $ rails server -p $PORT -b $IP
=> Booting WEBrick
=> Rails 4.2.0.beta2 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-10-30 21:44:22] INFO WEBrick 1.3.1
[2014-10-30 21:44:22] INFO ruby 2.1.1 (2014-02-24) [x86_64-linux]
Exiting /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `listen'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `each'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `foreach'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:459:in `tcp_server_sockets'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/utils.rb:75:in `create_listeners'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:132:in `listen'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:113:in `initialize'
from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:45:in `initialize'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `new'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `run'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/rack-1.6.0.beta/lib/rack/server.rb:288:in `start'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/server.rb:80:in `start'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `server'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/railties-4.2.0.beta2/lib/rails/commands.rb:17:in `<top (required)>'
from /home/ubuntu/workspace/hello_app/bin/rails:8:in `require'
from /home/ubuntu/workspace/hello_app/bin/rails:8:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /usr/local/rvm/gems/ruby-2.1.1#rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/ubuntu/workspace/hello_app/bin/spring:16:in `require'
from /home/ubuntu/workspace/hello_app/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
I've tried specifying a different port, but that doesn't work and the cloud9 environment suggests to me I should just use the $PORT variable.
The error "Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)" implies that I already have a rails server running, but I don't. I'm not really sure what to do here and the tutorial doesn't suggest any method of troubleshooting this issue.
I learned that you can use the command killall ruby to stop any of the ruby processes which helped me because I had mistakenly run the rails server -b $IP -p $PORT command at the ~/workspace level in the tutorial. I found the answer in can't open rails server
I ended up starting the tutorial from scratch again and it worked fine, but anyone with this problem in the future may find this troubleshooting technique I received from cloud9's support team useful:
Try:
lsof -i:8080
This will give the app that occupies it.
If apache, stop it using:
sudo /etc/init.d/apache2 stop
Hope this answer is of use to anyone with this problem.
Probably you just had the other server still running. The one you initiate earlier on in he tutorial with the rails server command. You need to shut the other one down first using Ctrl+C, then try rails server -b $IP -p $PORT again
$ rails server -b $IP -p $PORT
Cloud9 uses the special environment variables $IP and $PORT to assign
the IP address and port number dynamically. If you want to see the
values of these variables, type echo $IP or echo $PORT at the command
line.
It's likely that if you wait a few minutes (not more than 2), your OS will free up the port. If not, use a random port number over about 5,000 every time you run rails server, e.g.
$ rails server -b $IP -p 6789
Or, because your IDE is so sucky, you might consider using a different IDE.

sidekiq doesn't pick up the configuration file in the default location

Sidekiq failed to start with default configuration file in config/sidekiq.yml.
---
:pidfile: tmp/pids/sidekiq.pid
:logfile: log/sidekiq.log
While running the bundle exec sidekiq -d in a rails application root, it reports error:
You really should set a logfile if you're going to daemonize.
/home/canoe/.rvm/gems/ruby-2.0.0-p353#rails4/gems/sidekiq-2.17.2/lib/sidekiq/cli.rb:141:in `daemonize'
/home/canoe/.rvm/gems/ruby-2.0.0-p353#rails4/gems/sidekiq-2.17.2/lib/sidekiq/cli.rb:39:in `parse'
/home/canoe/.rvm/gems/ruby-2.0.0-p353#rails4/gems/sidekiq-2.17.2/bin/sidekiq:7:in `<top (required)>'
/home/canoe/.rvm/gems/ruby-2.0.0-p353#rails4/bin/sidekiq:23:in `load'
/home/canoe/.rvm/gems/ruby-2.0.0-p353#rails4/bin/sidekiq:23:in `<main>'
However, this should work according to the wiki since the config file is in the default path.
What's wrong here?
Ok. this was a bug in 2.17.2 , use 2.17.7 version. That's all.

Resources