Rails app deploy users - ruby-on-rails

I'm working on deploying my Rails app with Capistrano and the deploy is failing as it cannot create directory.
I have two users on my server:- root and deploy.
Capistrano is using the deploy user.
I have told Capistrano to deploy the app to /var/rails_apps/
It's /var/rails_apps/ that it cannot create a directory in.
What user should own that folder? root or deploy?
The server has nginx on it so I guess the site will run as www-data which looks to be nginx's user but I'm not sure what other areas should be owned by? Any clarification on this area?

deploy should own that folder. Nginx is just your web server, it is going to proxy requests to your application, which is likely running as a unicorn process (should run as deploy).

Related

How to run rails applications on digitalocean using "rails s" (make it a development environment)

My issue is that I created a droplet to develop Rails apps in digitalocean .
I used the one-click rails droplet. And now I want to create more rails apps than the default rails app in this droplet.
The issue here is that it comes installed with nginx/unicorn .. And they're always on with path of default rails project in their config files.
Now let's assume I created another rails app(file) and I want to run it using "rails s" instead of default rails app that is created by the droplet. How can I do it?
Note: I don't want to change the file path in configs each time I decide to try another app
PS: I tried stopping the service of unicorn/nginx one at a time and both of them in the same time to use "rail s" to run the app .. But it didn't work .. Web pages were not loading
I know it might be a question of a rookie. But I'm kinda new to these stuff and I'd appreciate it if anyone could help me.
If you run it with rails s on the server, chances are it will be running with Puma, or if you're on an older version of Rails, Webrick. Unicorn is not involved in that case because Rails is using its own default web server. If you see that 'rails s' is not running in the right environment, it may be because RAILS_ENV is being set in your shell profile. You can override that by doing:
RAILS_ENV=development rails s
To launch your console.
That being said, rails s runs on localhost:3000 by default - and in the case you described it would be running on DigitalOcean's localhost - not yours. In order to get to it from your local machine, you would need to set up some sort of reverse proxy to allow connections to DO to get served from localhost. This is what nginx is doing for you - it's facilitating a reverse proxy.
If you want do use your DO server as a development machine for a second rails app you have, you're going to have to create that new rails app on the server, then create the reverse proxy settings in nginx to direct to it, then finally create the unicorn settings to serve it. This is an uncommon way of developing though. I recommend using your local machine to develop, and setting up Capistrano or some other deploy tool to deploy it to DO instead. You'd still need to add the settings in nginx/unicorn for the second app, but it will save you headache down the road.

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.

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

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 application permission on apache

What should be the permission on rails app directory on apache server???
What is your deployment design?
Normally you'd use mongrels and apache as a load balancer for them.
So you'd run the mongrels as a user for your site, and all the rails directory should have permissions for that user.
You probably have a 'www' or 'apache' user that owns your static content and apache root document directory.
It's common convention to make this user own your rails app as well to preserve the same permissions.
If you use something like capistrano, I think it has builtin recipes for permission structure on top of your release directory after deploying.
As Angelus said, it depends on your server setup and deployment design. You can use mongrels (or thins, or unicorns, or...) with Apache as a reverse-proxy, but your question leads me to believe you're using Phusion Passenger (aka mod_rails).
If that's the case, the mod_rails site has several very helpful screencasts which you should watch. Generally, though, mod_rails will run as whichever user owns your app's environment.rb file. See the Passenger user switching docs for details on your permission setup.
While installing apache it creates www-data group and owner so you have to give the ownership of this user for your application.
Then restart the apache service.
rails application works fine.

Resources