How to stop rails nginx-passenger application? - ruby-on-rails

I use the passenger spawned by nginx. There are many other rails applications on the server that uses passenger (each has own virtual host in nginx).
I can restart the Rails/Nginx/Passenger application like this:
touch tmp/restart.txt
How I can stop it?
This doesn't work:
touch tmp/stop.txt
touch tmp/shutdown.txt

Method 1
Remove your app's virtual host entry and restart Nginx. Phusion Passenger will no longer serve it.
Method 2
In case you want to keep your app's virtual host entry, but not actually run the app.
Set the following option and restart Nginx:
passenger_min_instances 0;
Phusion Passenger will now shut down your app if it hasn't seen traffic for a while (~10 minutes). It'll be started again if traffic comes in for that app.
With passenger_min_instances 0, you can also kill the application processes manually. Look up the PIDs with passenger-status, then run kill <PID>.

Passenger is built to auto-run at all times.
As a workaround, you can stop the webserver entirely, or stop serving the particular app that you don't want to be served by removing the virtual host entry for it.
You could also uninstall passenger if you're really desperate

Related

Do I need to restart NginX after reconfigure for passenger to work

I just updated my NginX configuration.
In the config I've added a new server with a different environment for a rails application.
I've reloaded the configuration (sbin/nginx -s reload) and deployed the application to the right folder but nothing seems to happen, NginX throws 404 not found..
Is there anything more I need to do?
Do I need to restart NginX or passenger for example?
Turns out you don't need to restart.
Passenger isn't able to restart (as far as I've found out) and NginX only needs a reload.

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

Why it won't apply changes when using Nginx?

I've just switched from Apache + Passenger to Nginx + Unicorn
I used to command /etc/init.d/httpd restart after I added change.
Then all the changes used to be applied to Rails Application.
But with Nginx, even if I command service nginx restart, changes won't be applied:(
Why? and How can I fix this problem?
You need to restart unicorn itself. See http://unicorn.bogomips.org/SIGNALS.html
With Apache+Passenger, when you restart Apache, it restarts Passenger. Unicorn is it's own server however and needs to be restarted/reloaded itself.

Deploying Rails applications with Passenger and Nginx to VPS (EC2)

I've developed a couple of applications which I'm ready to deploy. To do so, I've configured Capistrano and I'm already able to run cap deploy, which runs properly. However, I'm totally lost as to how to continue from here. My setup is EC2 + Rails 3.2 + Ruby 1.9.3 + Passenger + Nginx (the one Passenger installs first time you try to start it) + Capistrano.
Until now, I just ran passenger start on my app root folder, which would start passenger on port 3000, and I would start the second app on port 3001. Now, what I need is to have this 2 apps under 2 different domains, say www.domain1.com and www.domain2.com.
How am I supposed to start the servers now? I can go to the respective current folders that Capistrano created and run something like passenger start -e production -p 3001 -d and it starts running as a daemon, but, shouldn't capistrano take care of this? All I see is that, on each deploy, it touches the restart.txt file and that forces a "soft restart", which is not enough (as far as I know) if you've changed gems. Shouldn't Capistrano be starting and stopping Passenger, not me?
How do I run the 2 apps on 2 domains? As far as I know, you can't point a domain to a port, and all I've managed to do now is to run 1 of the applications by running Passenger on port 80 with rvmsudo, but of course this only works for 1 application. After searching a bit I've found something about Nginx Virtual Servers. How do you do this? I mean, I have never touched anything specific to Nginx, just Passenger! Am I supposed to forget about Passenger and deal with Nginx as a service? How?
Thanks in advance!
I believe to start servers there's a specific cap command to start servers, but i don't know much about capistrano, just played with it a little bit before.
As for the second part, this is where nginx takes part, nginx will handle forwarding each domain to the specific port, using proxy_pass, take a look at this example
server {
server_name: example1.com;
proxy_pass: http://127.0.0.1:3000;
}
server {
server_name: example2.com;
proxy_pass: http://127.0.0.1:3001;
}

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.

Resources