How to Restart a Rails App on Shared Hosting
I have several clients who have their rails sites hosted on shared servers. To make these sites actually running smooth is such a boring task, not to speak the maintenance nightmare.
Most hosting companies don’t even provide good docs on how to restart your rails application (through ssh or capistrano of course). For example, on one company’s (I don’t want to mention the name) guide page for setting up Ruby on Rails, 80% of the guide is telling you what MVC is, how to create a rails app (yes, by run ‘rails app-name’), how to create a database, how to generate a controller and an action with view.
What’s the other 20%? Real useful information, such as:
cd ~/public_html/
rm -r myapp
ln -s /home/YOUR_USERNAME/rails/myapp/public myapp
and:
Congratulations, You now have a working ruby on rails application which reads information from a database. Go to http://app.yourdomain.com/controller/view and you should see Superman’s information.
That’s awesome! Now how could I configure the app to run under another environment mode? (99% percent of site owners would like to run production, but unfortunately the default one is development) What should I do if I need to redeploy the app and restart it?
Nothing! It’s top secret they’ll never want you to know, or find easily.
I’m telling you one top secret here! If you have SSH access, log in to the server, and run this command:
killall -u <YOUR_USERNAME> dispatch.fcgi
If you’re lucky enough, your rails app would restart, though the command might tell you that it fails to do something.
Another thing your clients won’t be happy is that some hosting companies are very eager to upgrade their rails as soon as a new version is released, and when they do it, they removed the old ones! This seems ridiculous and foolish. I experienced this three times this year, two when Rails 2.1 released, and one when 2.2 released last week! When this shit happens, your client would email you in the deep night:
Hey freelancer, I don’t know what happened but the site is not working anymore. Please take a look and take care of it. Thanks!
Finding out what the problem is, you ask your client to write a ticket requiring the hosting company to install the old version back. Sometimes they do, sometimes they’d tell you this piece of shit instead:
Dear customer, sorry we’ve installed the newest version of rails as we’re the most advanced hosting company in this industry. We won’t go back to the old version, never! You could install gems yourself to your own location though (we’re really advanced and truly helpful), and please add the following code to use your own bad old rails if you do:
$:.push(“/home/youloser/ruby/gems”)
Super awesome!
So what you’d say? Are you going to buy such shared hosting for a Rails app? Please don’t. VPS is much better, and just with a little more money. Choosing a shared hosting, you could save less than 15 dollars a month, but would spend much much more to keep your site alive.