How do i make nginx and passenger restart automatically after a deploy - ruby-on-rails

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.

Related

Deploying rails app on Digital Ocean with passenger and NGINX

This is the very first app I am deploying so I'm not 100% familiar with the whole process.
Right now, all my code for the app is on my server, and if i run rails s and bind it to my droplet ip, it shows up perfectly(i.e. if i go to myipaddress:3000).
But, if I just go to myipaddress on my browser, i just get a 500 error page.
I am confused about the whole process, do i have to have my rails s running the whole time when deployed and running on the server?
If not what am I doing wrong and how can i fix it so that it just shows up when I go to my droplet ipaddress?
My nginx.conf file has its server name pointed to my droplet ip and its root pointed at my apps root folder.
Also, im not getting any errors logged into my nginx/log/error.log file
First of all you don't need to start server with rails s.
You just need to install passenger and nginx for start application with installation of ruby on rails.
And if you just want to check your app is running or not then start server with rails s into digitalocean and try to open it with browser with `ip:3000' then it will work.
From this Ref. link you can start with passenger and nginx.
Let me know if you need more help.

Setting up Rails on Hostmonster

I'm able to run rails s through ssh successfully and see the app start up just as it does on my own machine but I'm unable to access the app from the web. The app is directly under the home folder and I have a symbolic link pointing from public_html to the public folder of my rails app, just as this tutorial explains. I even tried setting up a subdomain and every other step in the tutorial to no avail. Any help would be highly appreciated.
You need an application server like Phusion Passenger, Unicorn or puma to run a Ruby app in a production environment. Typically, you'll integrate the application server into a web server's (Apache, nginx) environment.
I don't know about your hoster, but if you have root access, then you can probably use any of these application servers.
The built-in server you start by running rails server is only meant for testing purposes on your local machine. It has not been made with security, performance, stability or any other production-environment criteria in mind.

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.

Passenger Hanging after Restart - Shared Hosting Environment

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?

Restart only a single Rails app running on Passenger / nginx on VPS hosting many passenger apps

I am running multiple rails apps and a sinatra app under the same domain on a VPS using nginx and passenger. When I deploy code I need to restart the application process for the app that got updated. Right now I'm running service nginx stop followed by service nginx start thereby restarting all the passenger processes. It seems silly to have to restart nginx instead of a just the target passenger process. Is there a way to do such a thing?
Here's my nginx.conf file: https://gist.github.com/srt32/8535548. Thanks.
Goto the root of your Rails application and touch a tmp/restart.txt file.
touch /webapps/mycook/tmp/restart.txt
Remove restart.txt once application is restarted, not mandatory though.
Reference - http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_redeploying_restarting_the_ruby_on_rails_application

Resources