Restarting Rails Application - ruby-on-rails

I am building an application that will only be run on a local network and am looking for the best way to restart my server from within the application itself. For the time being this is only running on Windows using WEBrick.

Look at Capistrano as others have suggested, it's fantastic :)
$ cap deploy
That's all you have to do. It'll grab the latest source from your git/SVN repo (lots more supported ofc), deploy, and restart your app server.

Related

deploy a rails app with capistrano without a rails environment

I've been working on a rails project for a client that isn't technical. However, they want me to send over a deployment script, which their networks guys will use to deploy the application.
I've been using capistrano. But the problem is, cap is heavily dependent on the app itself. What i need is a script, that'd use the cap and config/deploy.rb but needs minimal setup on their local systems. The repo in the backbone is git based.
If this cant be achieved by capistrano, anyone knows of any other deployment utilities, that'd allow me stuff cap does and works independently? .. (i create symlinks and run some rake tasks in my :after_update block).
Thanks,
Hassan
If setting up a ruby environment to run cap deploy is not something that the "network guys" will be willing to do, then you're in for quite an uphill battle. Some suggestions to help alleviate this:
Have them use the railsready script to set up their environment
Give them a virtual machine (maybe a Vagrant box?) that can be used to deploy the instance
If you're doing a git-based deploy, you'll either have to set up a deployer key (and give this to them) or add them to your github project (assuming you're using github)
Consider bundling up the entire project and delivering as a tarball (or putting it into an rpm) and having them deploy this way (a quick&dirty way to do this is to deploy to a machine running the same distro as production, and tarring up the deployment directory)
Consider using a stack that more aligns with their network stack, like JRuby and warbler for deploying to Tomcat
Do some pair programming or at least screen sharing for the initial install. Sometimes the difference between loving and hating a platform comes down to the availability of help when problems arise.
Mina is like Capistrano but doesn't rely on being inside the rails application directory.
One option could be to setup something like Jenkins that will use capistrano to deploy. And your client can curl the jenkins build url to trigger a deploy.

What, where and how to upload Ruby on Rails application files to the VPS?

I am using Ruby on Rails 3.0.9 and I would like to publish my web site. I already set my VPS running Ubuntu 10.04 LTS and the capistrano gem (this one I think as well as possible). Now, what I need to do is to upload all files to the www/project_name directory (I am on Mac OS)...
What I have to do to accomplish that?
You don't need your deployment machine to have Capistrano. Capistrano automates a bunch of tasks that I suggest you do at least one manually so you know what's going on. Sooner or later, you'll be debugging some Capistrano task, so you may as well figure out the guts sooner or later.
Coarsely, what you need to do is to basically duplicate your development environment on your production machine. If you have it on version control, you can git clone or svn whateveritis on your production machine. If not, you can scp it over with scp /local/rails/dir remoteuser#remotehost:www/projectname.
At this point, you should actually do the remainder of the work on the server. Since you've managed to install Capistrano, I assume you're familiar with the basics of making your way around SSH.
Once the code's over, you have to install the prerequisites. If you're using 3.0.9 you should be able to run bundle install --deployment, where the deployment flag basically tells bundler to use the identical gem set as on your development machine.
When that's done, actually getting the server online will vary based on your setup. If you're using non-standalone passenger, just follow any of the many guides at this point. If you're running standalone passenger or thin or unicorn or any other standalone rails server, go ahead and start that in daemon mode (so it won't quit on you when you end your SSH session) and make sure you se the production flag. You can either start it in sudo and have it listen on port 80 (e.g., sudo thin start -d -p 80) or have it listen on a higher-number port and use a reverse proxy on your WWW-facing server. The instructions for how to reverse proxy are all over the internet.
Let me know if you have any questions.
You have half of a deployment solution with Capistrano. Commonly Passenger is used as the other half, which sits on the server and loads your app. To accomplish this, usually, SSH keys are used. There are numerous tutorials on how to set this up. One of my favorites written by Dan Benjamin can be found on his blog Hivelogic.
Edited to provide more begginer info:
Capistrano begginer's guide from the Capistrano wiki.
Passenger Stand Alone Guide from the Passenger website.
Be sure to check out the other guides for the webserver of your choice when you're ready.
These guides will give you the background you need to get a local Passenger & Capistrano deployment going. These guides provide the knowledge you need to get achieve what you want.
Simple and short sample of deployment via SSH http://alexeypetrushin.github.com/vfs/ssh_deployment.html

Getting rails application from github to debian server

I've been developing my first rails application on my windows computer.
But now i have been setting up a debian server with nginx and passanger.
I've been using Github to keep track of my application and now i am wondering how i can get the Github version of my application to the debian server and put it in production mode?
Anybody that have a good guide about this or something?
Getting the code to your production server is just the tip of the iceberg. What if you want to rollback to the previous version? Or tag a specific version and deploy it? How will you deal with different versions of configuration files for your development vs. production scenarios?
That's why you need Capistrano. It lets you do all this (and more) from the command line of your development machine. Take a look at the "From the Beginning" chapter to get started.
You'll also need some basic knowledge of shell commands and SSH.
Also have a look at the Phusion Passenger docs to see what is needed on the server side.

How do you deploy your Rails application?

Do you upload your rail application to your host via FTP first?
I'm currently using Passenger and Capistrano. If I do "cap deploy" in my local machine then I think Capistrano should upload my rail application to my host, right?
Someone from my host is saying that I need to run "cap deploy" in server. I think it doesn't make sense.
You should be able to run cap deloy on your local machine and that should get the current version of your software to the server. However, you need to set up first how this is supposed to happen. I for example use Git to manage my code and also use it to get my software on the server. However, you could also use SVN or FTP if you prefer that. If you google for Capistrano together with the Software youbeant to transfer the code with and maybe even your hosting providers name, you probably will find a decent step by step explanation. For me John Numemaker's post on deploying with Capistrano and Git on Dreamhost really helped: http://railstips.org/blog/archives/2008/12/14/deploying-rails-on-dreamhost-with-passenger/
As an alternative you also might want to check out heroku.com. Their smallest offer is free and enough for most projects. The deployment process is so easy a monkey could deploy a Rails app on their platform. I generally can only recommend heroku.

RoR Server Construction and Capistrano Support

I have been creating a website with Ruby on Rails, and will be hosting it through a friend. He has the space and capacity to host the server, and I have a system to devote to being a dedicated server. And this is my first attempt at a Rails website, plus self-hosting with a friend.
I will be formatting and preparing the server today and tomorrow with the following software configuration:
Apache2
Phusion Passenger (aka, mod_rails)
Ruby Enterprise Edition
MySQL 5
I do have a number of questions, and I apologize for their complexity. I haven't found a guide for this configuration yet, and being new to Rails I haven't the experience to navigate my way through this yet.
What build of Linux is most recommended for this configuration?
I have been planning to deploy on CentOS. The caveat is that I have been a Windows user since my early days, and have only used Linux as a webhost and very few development commands (such as CVS). Thus my knowledge of Linux is rather small, and my experience smaller. If I run into any deployment snags, technicalities thanks to the distro of Linux, or anything of the sort ... I'm totally hung out to dry.
This includes things like building anything from source code.
How do I set up Capistrano on my server for remote deployment?
I know this is an oxymoron (Capistrano is client-side, not server-side) but I don't know what it needs on the server. Does it need FTP? SFTP? SSL? SSH? What?
What do I configure on my server, and how do I configure it, to enable Capistrano to run smoothly?
Also, how do I refer Capistrano to the fact that my SCM is on localhost and is by Mercurial? (I used TortoiseMg.) I could convert to SVN and probably set up a repository on the server, but I'm not entirely sure how to do that.
What is the biggest snag you watch for when deploying from a localhost development, to deployment on a totally different OS?
Miscellaneous
Why not deploy to Windows then? Because I'm footing the bill, and I don't want to pay for another copy of XP or possibly 2000; I refuse to use Vista. Plus, Linux is much more secure than Windows for a server environment.
Why not read the existing guides? I am; this is my first site with Ruby on Rails, my budget is in the less than double-digits area now, and I'm trying to expand my horizons by doing the server configuration and the remote deployment (for further development of the site) by myself. I've relied on hosts in the past for my PHP websites, but they're much more homogeneous in their configuration. Ruby servers are expensive, prohibitively so for me, and to learn its configuration wouldn't hurt to know.
What build of Linux is most recommended for this configuration?
Any of the distributions will work fine as long as they can run Apache2 (which is almost all of them) and you can install Passenger (along with ruby and rails).
I personally use CentOS and find its package manger to be ridiculously easy to use (yum).
yum install -y httpd ruby
gem install rails passenger
Then all you have to do is a little configuration in /etc/httpd/conf/httpd.conf to add Passenger (following the install file for Passenger passenger-install-apache2-module) and point it to your deployment folder .../app_name/current/public.
Since you are using Passenger you should override the restart task to work for it.
config/deploy.rb
namespace :deploy do
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
end
How do I set up Capistrano on my server for remote deployment?
All Capistrano needs is SSH access with sufficient permissions to deploy, migrate, restart app server, etc. Just follow the getting started guide at the Capistrano website and you will be up and running in no time.
Capistrano needs access to your SCM, you will need to allow it to connect to your machine. All Capistrano does is checkout your code into a release folder and moves the symbolic link from the old version and restarts your app server.
What is the biggest snag you watch for when deploying from a localhost development, to deployment on a totally different OS?
The biggest snag is with migrations, test, test, test, and test them some more. A bug in your application is easy to fix and redeploy, but a bug in your migration could end up a huge pain in the ass with the possibility of data loss.
I've found the articles posted at Slicehost.com (a VPS hosting company) to be pretty helpful.
The full list of articles are at: http://articles.slicehost.com/sitemap . You'll find a number of articles there related to production deployment of a Ruby on Rails application.
I recommend using Ubuntu server and deprec, as it provides a ton of sysadmin recipes that make things even easier.

Resources