Redeploying (Updating) Rails App w/ Phusion Passenger - ruby-on-rails

I have what I hope is a simple question. I'm pretty new to rails/web apps, so I apologize for any obvious lack of knowledge demonstrated in asking this question.
Essentially, I've been updating/maintaining an existing Rails app that I didn't develop/deploy. Up to this point, all the changes I've made are so minor that I felt comfortable doing them live (undesirable, I know), but I've recently had to make some changes that involved installing some new gems and updating the database. To do so, I pulled the app/db from the production server, recreated the production environment, and made all necessary changes locally. Put simply, my question is: what is the safest/easiest way to update the app/bundle/db on the production server?
I know there are myriad tutorials regarding deployment with Passenger, but I haven't been able to find anything that specifically references updating an app that's already in production. Is there a distinction between initial deployment and redeploying an updated app?
Tech stack is Ruby 1.9.3, Phusion Passenger on Apache, and PostgreSQL 9.1.3.
Thanks in advance.

You could simply upload the code, run bundle install then bundle exec rake db:migrate and call it a day, but the standard procedure would be to use something like Capistrano, for which myriad tutorials and guides are available on deploying Rails apps.

Related

How to deploy a rails project on a Ubuntu server?

I've developed my Rails project locally and want to deploy it on my Ubuntu VPS. Now I've installed the gems on the VPS and copied my Rails App code to it. I can execute rails s --binding=0.0.0.0 in a putty session to the VPS and the website can be access from the Internet. The problem is when I close putty, the website is down. How to start my Rails App in a way that it still alive even if I closed putty?
Using rails s is not the way to go. It will use Webrick(or a different one if you choose) to handle the requests and it can be quite slow.
You should setup a production stack for serving your website.
Here is one of the best tutorials I've seen about how to deploy a Rails app to a production server(VPS).
In short you gonna need install RVM or Rbenv, Ruby, some libs, Database, Nginx and Passenger. You have alternatives too. But this is the basic.
I recommend using Capistrano for deploy. You can choose another deployment tool also, or none.
rails s it is best for development only.

Upgrading ruby on a production server with Rails and Passenger

I have a few Rails apps, each running on their own server. They run under Passenger-apache, and currently under ruby 1.9.3. Currently, they run under a ruby installed and managed with rbenv.
I'd like to upgrade them all to ruby 2.2.x. As long as I'm doing this, I'd like to upgrade them from passenger 4.x to 5.x as well.
Let's assume I've tested them all on my development box and am confident they run fine under ruby 2.2.
As I think through this, I get very confused about the best way to do this -- especially with minimal production downtime.
I guess I'd start out by installing ruby 2.2 under rbenv, which theoretically shouldn't disturb the running apps. Passenger is installed under a particular ruby, but then has the option of running apps under different rubies. Should I install the latest passenger first, under the new ruby 2.2, but configured to run the existing apps under the old ruby? And then upgrading the apps to the new ruby... I guess involves running bundle install again, to get all dependencies installed under the new ruby?
Or something else entirely? Is there a way to do this that is relatively safe, and will have limited or zero downtime for my apps?
Has anyone done this before? I'm fairly familiar with all the pieces already, and can brainstorm possible approaches myself, but when I start, there are too many places where I'm not sure what the best approach is. What I could really use is advice from someone who has already done this, or is otherwise pretty sure that what they recommend will work as they say -- not just guesses about things you haven't done that might work. Thanks!
Make sure that your applications work under the new ruby version. I have had some legacy Rails 3.2.x applications that works up to ruby 2.1.5, but breaks in ruby 2.2.x. You should be fine with updating your ruby and passenger versions.
Since each application runs on their own server, you don't have to really worry about running multiple versions of passenger. You should be able to install the new version ruby on each server, install the gems, update apache to the newer passenger and restart apache to have everything take effect. Worst case, you can clone your servers to a virtual environment and test everything prior to doing it on production. This would help you minimize downtime as you would have any workarounds and/or research of bugs done prior to touching the production environment.

Locomotive CMS app crashes after Heroku deploy - Couldn't load redcloth_scan

I have an instance of Locomotive CMS running on Heroku and it has been running fine for about a year. I am the only developer so there have been no deployments since the last working deployment.
Yesterday I made an update to the config/environments/production.rb - all that I changed were the values for the existing ActionMailer settings. Committed and pushed, et voila - the app no longer functions.
The app works on the dev machine, when run in production and dev mode.
I'm a newb when it comes to Rails and Heroku, so I'm having some difficulty interpreting the log.
I've posted the log at: http://pastebin.com/GZpRaue6
The only clear error that I can see in the log is:
Couldn't load redcloth_scan
I have tried adding gem 'RedCloth' to my gems file and bundle installed, as it wasn't explicitly required in the original version of the source, but this has made no difference.
There is no mention of redcloth_scan in my gemfile.lock, but RedCloth is listed as a dependency of Locomotive.
locomotive_cms (2.0.0.rc9)
RedCloth (~> 4.2.8)
After much messing about with the gemfile, each gemfile alteration simply causing different problems with loading the binaries for a different gem. So not an issue specific to redcloth.
I came across this SO post: What is the purpose of vendor/bundle? Heroku tells me to remove it
This use of --path is certainly not an elegant solution, my app never needed this before - something must have changed in Heroku and I'm hoping to be able to move away from this in future. But it's fixed it for now and that's good enough for me.

Can I deploy a Rails App directly onto my companies website?

I have originally been hosting my apps on Heroku, however this is not an acceptable deployment method in my current environment. We have personal information in our applications that deploying to Heroku and setting up DNS forwarding is not acceptable. Regardless of how 'secure' or 'reliable' anyone may think it is, it is just not acceptable in my case.
Our host is siteturn.com, integrated with Plesk 10.4.4. If I SSH onto our websites server as admin and type
ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux].
rails -v
Rails 2.3.5
It appears Ruby and Rails are already installed (Older versions than I require, as I need ruby 1.9.3 and Rails 3.2) If I'm not mistaken it seems like my host 'supports' rails (why else would it already have it installed :P).
How should I go about deploying my application directly onto my companies website?
Heroku is an awesome service but the ease of deploying to Heroku has given you a skewed view of what is involved in hosting your own rails website. Heroku has shielded you from a lot of the hard parts.
For example, just because ruby and rails is installed does not necessarily mean you can host a production rails website. You'll need a rails specific web server (for example nginx and passenger, unicorn, etc). You also need a database (MySQL or Postgres) assuming your web app uses one. Also, as you said you need to upgrade the versions of ruby and rails.
That's just to get the server setup. After that you can get to the deployment part. Capistrano seems to be the most popular choice right now.
Take a look at this railscast episode on deploying to a virtual private server for a very good overview of what is involved. It also briefly goes into Capistrano as well. It's not a free episode but I feel it's definitly worth the money.
Pick up a copy of Agile Web Development with Rails, Third Edition and read what it says about deployment. That should get you started. There's more info required than can be put in a SO answer.

De-capistrano a rails app?

I've inherited a rails site that I need to deploy (quickly!) to our webhost, which is a standard *nix shared server that uses FastCGI for rails apps. I've worked with rails sites on multiple occasions in the past but wouldn't consider myself an expert by any stretch.
This particular app was developed using capistrano, with which I've got no experience, and everything I've read leads me to believe that to deploy the app "properly" would require my setting up an external svn account, among other things, which aren't feasible given our time frame and hosting situation.
My question is: what is the best way to quickly get this application up and running without using capistrano? I received, along with the site files, a .sql dump that I've already imported, and I've configured config/database.yml to reflect the correct production db settings. Right now, running ruby script/console production yields the following error message:
/home/user1/ruby/gems/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:443:in `load_missing_constant':NameError: uninitialized constant ApplicationController
Thanks for your consideration!
As the others already stated, you are probably using the incorrect version.
Rails switched from app_controller to application_controller (or something like that) in version 2.1 or 2.2.
There is a rake task that you should be able to run in that case:
rake rails:update:application_controller
It might help you.
As for the capistrano. In your deploy.rb you can add the parameter :deploy_via :
set :deploy_via, :copy
set :scm, :none
And it should use the copy you are having in your working directory to deploy with (no need for subversion or any other version control)
Copy usually fetches the code from a repository locally and then uploads it to the server, but also setting the :scm to none it should ignore that and just (hopefully) use your working copy instead.
All capistrano requires is a deploy.rb and a Capfile, this is not what is causing your error. From the looks of it it seems that the problem is that you're using a gem rails version which is incompatible with your app, do you know which version it was developed with? If so you should try vendoring your rails directory to the right version.
For deployment, if you're using FastCGI you can just upload the files to the host and set the appropriate permissions and you should be good to go. Going forward you might want to look at upgrading to a newer version of rails, using capistrano and changing your environment to use apache passenger.
I hope this helps.
The problem you're running into appears to be a mismatch of your installed version and the version that the app is expecting. Look in config/environment.rb, Toward the top you'll see something that looks like:
RAILS_GEM_VERSION = '2.3.4'
You need to make sure that the version of rails installed on your machine matches whatever version is declared in that file. You can do that by running:
sudo gem install -v=X.X.X rails
where X.X.X matches what was in your environment.rb.
Jonnii is suggesting you "freeze" your rails by including all the rails code into your project directly, (which can be done by running rake rails:freeze:gems AFTER you have followed the above steps and gotten the correct gems installed in the first place.) Once you've frozen rails, then you no longer need to have the rails gems installed on your webserver machine.
Good luck!

Resources