Deploy ruby on rails via Capistrano - ruby-on-rails

I have successfully deployed my ruby on rails application to an ubuntu 14.04 virtual machine in Digital Ocean. I used Apache2 and passenger for the same.
Now I want to deploy it to the same using Capistrano. I am using a mac machine in the developer environment. I have installed Capistrano 3.4. ssh connection has been set up with my local machine and server as well as with my server and my mercurial version control system in bitbucket.
How can I deploy it via capistrano. I tried many tutorials. Many are outdated and I am not even close. I have deployed it in the server in uat environment and the source code is checked out and is kept in the desktop of server. I have also set up a user with sudo privileges.MySQl2 database is also in the same server.Please help me out .

You can see the gist here, there are 4 files
deploy.rb
production.rb
capfile
Gemfile // only the capistrano required gem snippet
But I've configured using nginx and passenger.

Related

Unable to restart production rails server when started as daemon

I am running a rails server on an Ubuntu EC2 instance and have run into an issue when it comes to deploying (and restarting) my server. The odd thing is; everything seems to work fine when I start a vanilla server (rails server), but when I start the server as a daemon it does not reset (rails server -d).
I use Capistrano to do deployment. As far as I can tell there is no issue; it pulls down my latest branch, runs migrations and does a touch tmp/restart.txt. I had tried making my tmp/restart.txt a shared file, but that does not seem to be the issue (although it is a configuration I think I'll keep). After discovering Capistrano is likely working as expected I tried sshing into the server and running touch tmp/restart.txt myself. It works for the vanilla server but not the daemon.
Has anyone seen this issue before? If there is more info I could provide please let me know!
Env:
ruby 2.6.3p62 #/home/deploy/.rvm/rubies/ruby-2.6.3/bin/ruby
Rails 5.2.3 #/home/deploy/.rvm/gems/ruby-2.6.3/bin/rails
Bundler version 2.1.2 #/home/deploy/.rvm/gems/ruby-2.6.3/bin/bundle
Node v13.8.0 #/home/deploy/.nvm/versions/node/v13.8.0/bin/node
My logs, tmp, and config/master.key are shared as part of my Capistrano setup.
are you using puma or unicorn or passenger? apache or nginx? restarting the process depends more on that than anything.
personally, I like using Passenger with apache and when I restart apache, the passenger process restarts automatically.

How to install/update rvm on a remote EC2 machine

How to install/update rvm on a remote EC2 machine, since we would like to deploy our rails app and its dependencies on new EC2 instances.
use rvm-capistrano => https://github.com/wayneeseguin/rvm-capistrano#readme it has quite good description how to setup everything, I maintain example project to make sure it all works as expected: https://github.com/mpapis/ad - you can check it's capistrano config for details

How to deploy Rails project in Nginx server using passenger?

In my local, I am using werbrick application server for my localhost.
I have Ruby version 1.9.2 .and Rails version 3.1.
How to deploy On live,with Rails Project On Nginx Server?
And What will be the application server (like passenger module with apache) can be used with Nginx server for Rails 3.1 application?
This blog post should give you a good starting point. This one here goes a little deeper in detail. Note: I used these to get nginx running on my local development machine (OSX 10.7) and to host different rails apps locally without using Webrick. Probably there is more to take care of on a live / production system.

Special Steps for Rails Deployment?

I'm Deploying a rails app on the server for production? What are the special steps, I should follow in production installation, that is different from development.
I've installed passenger, passenger-apache2-module
I've also run bundle install --deployment
What are other special treatments, I should use for production?
Thanks.
With our deployment servers we have a fairly easy setup
ubuntu
apache + passenger
a rails user from where the apps are
actually run "/home/rails/apps/fancy_app_name"
and we have a webistrano app running to handle the deployments (so our development
machines don't have to be aware of all production steps)

Correct way to set up Rails environment?

Thanks Tilo for your response. I will try to ask a better question.
I need to set up a Ruby on Rails Production environment that will only be used to host RoR applications and will be used as a Git server too. There will be no development done to these applications on the Production server. Right now, I forsee the production server hosting a maximum of 5 to 6 applications only. A couple will be company internal only and the rest of the apps will be viewable to the public. The traffic that they will receive is about 12 to 20 hits per week.
I have been given access to a Virtual Machine that will be the Production server and is currently running Ubuntu 10.04 LTS, Apache2, MySQL, and Passenger. There will be two RoR developers using the Production server to host their applications.
My Development Environment of which I am running Ubuntu 10.04 LTS, Apache2, and MySQL on my own laptop looks like this for each project/application:
RVM installed per application, Git,
Ruby 1.9.2 installed thru rvm, Rails
3.0.3, and I have yet to install the Capistrano gem.
My question is I don't understand how to host a RoR application on our production server.
As an example of what might be done to host a RoR application: I am surmising that I will create a user called app1 under the home directory. Next, should I install Ruby system wide or should I install rvm for app1 and then Ruby for app1? What are the steps involved on how to set-up the environment to run an application on a production server?
Can you give me a few setup scenarios, please?
Thanks in advance.
You didn't tell us what you want to use this web-site for... is it company internal only?
just a few users? or is it externally facing the internet? Just one server running everything?
If it's facing the internet, I would certainly stay away from Ubuntu... look at CentOS/RedHat or FreeBSD to install on a production server.
I'd definitely use Capistrano for deployment. Definitely Git.
I would definitely not install RVM system-wide - IMHO it is not robust enough.
I emailed with Wayne Seguin (maker of RVM) and he also uses the method I've outlined in the post below,
using one dedicated deploy user:
For how to deploy ruby-versions and gems with RVM, look at this post:
Installing Ruby offline using rvm
If you really need two versions of Ruby for two different apps, then use two deploy-users!
Each of them has their own default-ruby-version(!) that's why you really need two users :)
and you can install / manage the gems for each project separately under each of the deploy accounts.
You should also put the git repository in each of the accounts, so you can test.

Resources