Passenger Hanging after Restart - Shared Hosting Environment - ruby-on-rails

Last night I made a revision to [app-root]/config/initializers/refinery/core.rb and the touched [app-name]/tmp/restart.txt. Then I tried to reload the app to find it totally hanging. The other two RoR apps I'm running on the same server were also hanging. Per curl -v there was no response at all from the server.
Everything was working fine before I touched the restart.txt file. The following morning, seven or eight hours later, the sites are working again and my minor edit (the site name) is showing up.
Rails 3.2.16 on a hostmonster linux server.
The instance of Passenger is not running under my user so I wonder if my hang horned any other user's RoR sites?
I can't restart apache (of course) since this is a shared server. Any suggestions for how to deal with this if it happens again? I have no budget for Heroku or a VPS.
UPDATE: Did the same steps again this morning, revised the core.rb and asked for a restart by touching restart.txt and it restarted in less than a minute. The question remains valid I think - what can a person do to address a hanging Passenger or prevent it from happening?

Related

Err max clients reached Redis/Sidekiq/Rails

I have been stuck on this issue for the past 3 days and unsure where to look now.
I have a simple Sidekiq implementation into my rails app.
I am working on: Rails 4.2.0, Sidekiq 4.1.2, Redis 3.0.6
The production app is running live with heroku, and I have 1 worker dyno and 1 web dyno.
The issue is this, and I am unsure on how to approach it or what I did to make it do this.
When I run the redis-cli on heroku I can see the clients that I have running. At most I have 2 or 3 clients running at any given time. I can easily kill the clients with
CLIENT KILL TYPE normal
So that's all fine and dandy. The part when things get a little tricky is when I fire up my server locally, and I am working in development. All of a sudden my redic-cli shows that I have 19 clients running. This will result in me logging
Err max clients reached
My assumption is that somehow locally I am directing sidekiq to work off the redis production url. I have to admit what I know about Redis and Sidekiq is limited, but I do have a basic understanding of how it should be working.
Any help or guidance would be appreciated.
Try using sidekiq -c 3 to limit your concurrency.
This ended up being a configuration error. Just in case anyone stumbles upon this question hopefully this will help them not overlook something like I did.
This issue was happening only when I was firing up my local server, so I knew it had something to do with me locally. I noticed that on my production redis:cli I was seeing clients that had my local IP in the ADDR column.
This led me to believe that my local machine was pushing clients to my production Redis server. Looking at my logs when I fired up my Procfile I saw the Redis url there so that only confirmed it.
Finally after searching through my code, I discovered that I had actually added the url into my .env, so when I fired up my server it was using that production Redis url. So I changed it to the appropriate IP address for local development on my .env file redis://127.0.0.1:6379 and everything is now working as normal.

Rails 3 app boot problems on development mode

I have Rails 3 app on server.
It works just fine, but pretty often fails to boot.
I have tried to run tmp/restart.txt to restart Phusion Passanger server, but there is no change at all. It can be even half-hour to finally get access to my app.
I reviewed my log files, but there is no sign off any errors ore something other that could cause such major delay.
I tried to test my app using New Relic but even there was no succes to actually connect my site, with no errors at all.
Try using passenger-config restart-app to force Phuson Passenger to restart your app.

How do i make nginx and passenger restart automatically after a deploy

I currently have a rails app deployed on a virtual private server.
I use Capistrano, Nginx and passenger to run my rails app on the server.
For some reason I can never get the updated code to display on the site after i have done a cap deploy:update.
The deploy happens fine and the code is even seen on the live server via Vim but if I navigate to the live site it won't display.
My current workaround is rebooting the server, starting nginx and passenger after the server boots back up.
my concern is if someone is logged on to the site when i deploy and restart, it will knock them off the site.
Does anyone have any ideas
If you run touch tmp/restart.txt from your rails root directory, passenger will restart the app. You shouldn't have to restart nginx. After the timestamp of the restart.txt file changes, Passenger will restart for the next request. If your app takes a while to boot, you may want to force this by making a request immediately after touching the file.
You don't need to worry about kicking someone off the site, it won't restart the server if there is a request in process.
If you are still facing the problem you can use Monit gem, in capstraino it works really well.

Rails environment deployment issue?

I'm trying to deploy my first Rails app here, and I've been stuck on something since last night. I'm encountering some weird behaviors I can't explain.
I'm running Rails, Apache, Phusion Passenger, and for the moment, SQLite 3. (I'll move that over to MySQL shortly.) Currently this is being hosted on a too-small EC2 slice running Ubuntu Server 11.04 (Natty).
When I visit the address of the EC2 slice in the browser, I get the default Rails 500 notice. Here's what's weird, though. When I tail /log/production.log, I see the following error:
ActionView::Template::Error (SQLite3::SQLException: no such table: offers: SELECT "offers".* FROM "offers" WHERE (code = '') ORDER BY created_at desc LIMIT 25 OFFSET 0):
So, I manually opened up the development database in SQLite3, and saw that table in there. The production database, however, does not have that table.
OK, so I'm getting errors with the production database logged in the production log. The application has to be running in production mode, right?
That is what's throwing me. First of all, it's running in development mode on my development machine, and I didn't change any of the files when I deployed it. Neither did I use any fancy deployment tools to deploy it (which may have switched something without my knowledge) - I just did a simple git push.
Furthermore, I added the following to my httdp.conf VirtualHost config:
RailsEnv development
Also, when I run rails console, I can get the following:
irb(main):002:0> Rails.env
=> "development"
So, the application really should be running in development mode, right? In fact, it seems to think (partially) that it is, right?
I'm really not sure what's happening here, and I'd really appreciate some expert advice.
Thanks everyone.
Edit - A few server reboots later, and now the thing just hangs when I try to view it in a browser. Also, Apache seems to hang when I try to restart it (hence the server reboots), related problem, or different problem altogether?
Well, this isn't a 100% satisfactory answer for me, but I did two things, and I think I got it working.
First, I re-installed the passenger Apache module. That may or may not have been necessary.
This was the big thing, though: after I had added the line to httpd.conf to pass the Rails Environment over to Passenger, I believe Apache restarted incorrectly. (Rather, I believe I've been restarting Apache incorrectly for my whole life!)
I was trying to restart Apache this way:
sudo /etc/init.d/apache2 restart
That has always worked for me (when programming PHP), but it simply wasn't working here. Apache would just stall on the restart.
This, however, works fine:
sudo apachectl restart
I'll have to ask Server Fault what the significant difference is between the two.
I hope that helps someone out.

Apache+Passenger - Apache running; but not responding to requests

Background
I'm running a Ruby on Rails application that has to serve a lot of static files as well.
My setup currently is:
Debian Linux Lenny 5.0
Apache 2.2.9
Passenger 2.2.10
The problem
Everything runs fine. I see apache process spinning up, passenger instances get created and everything works fast and snappy.
Then, after some time Apache does not respond to requests any more. Clients do get a connection and are "waiting for a response", but none comes.
I cannot manually reproduce this problem. Sometimes it occurs a few hours after a restart, other times it takes a few days to happen. Here's what I found:
Apache process are up; Passenger is there, but it does not have any instances spun up (probably because instances die after a period of inactivity)
No error messages or problems in /var/log/syslog, /var/log/messages, not in apache's access and errors logs, not in my Rails production log. Nothing.
When I stop and start apache everything is back to normal.
Does any one have any clues what's happening here? And how it can be resolved?
Due to an enormous load on static files we decided to host static files on separate server (later Amazon S3+CloudFront) for performance reasons.
My current guess is that Apache couldn't cope with the large number of requests on static files and also doing Passenger. The current setup is Nginx+Unicorn for the Rails application and S3+CloudFront for static files.

Resources