How do I deploy a Rails 3 applications on Windows? - windows

I've been searching for a way to reliably deploy a Rails 3 application on Windows. I'm quite shocked that it seems like there isn't currently any way to do this. The Apache + few Mongrel services solution don't work currently because Mongrel cannot run in daemon mode therefore I can't install it as a mongrel_service.
The requirements I guess should be:
A web server compatible with Rails 3.
Must be able to run as a Windows service, daemonized.
Must be able to restart automatically in case something goes wrong.
Must be production quality: no memory leaks, etc.
Should be able to scale, and accept multiple requests concurrently.
Less hacks possible.
I found out these things:
Mongrel is not production ready for Rails 3 (1.2.0pre), I experience memory leaks quite fast from a console window. The app just exits.
Mongrel doesn't run in daemon mode (-d) with Rails 3.
Therefore Mongrel cannot be installed as a service.
Phusion Passenger is not available on Windows (would be the best solution).
These are the possible solutions I came up with:
Get a Linux box, install Apache + Phusion Passenger and roll.
Using thin, however, the author says the thin process is not 'guarded'.
Using Ngnix, however, the author says he just ran a default app, not a full run app.
Using Ngnix. I think this solution suffers the same problem as above.
Using a virtualization of Linux, but I must solve problems like auto-start, etc.
Run on JRuby within Tomcat.
This might be a handy tool: http://projectkenai.com/projects/winsw
I hope we can find a real solution to this issue.
Update:
I agree that JRuby + a j2ee container is the best bet. Some problems must be resolved like gems with extensions, etc. There are lots of valuable ideas here: http://rails-nutshell.labs.oreilly.com/ch14.html#production_r259035_id35801805

This is the setup I currently have running:
Windows server 2008
Apache 2.2
Thin Server
Ruby 1.9.2
Rails 3.0.9
Installation of these aspects is covered by this great tutorial "How to install and configure Ruby on Rails with Windows Server 2008 EE". I ignored the LDAP and ActiveDirectory bit, but there is a nice workaround discussed there for installing Thin server since gem 'thin' will normally break on Windows.
For production I set up MySQL Server 5.5 to host my database. The mysql2 adapter is required for Rails 3 but is not yet supported in my Windows environment. The mysql adapter will also throw an error on Rails 3, but as a workaround you can get it to work by installing an older version of libmysql.dll. You just need to drop it into your Ruby192/bin directory.
Once the proper mysql adapter and server is installed you'll need to create the database:
>> mysql -u root -p
[enter root pw]
create database production;
quit;
(You may need to add your MySQL installation to your path if 'mysql' cannot be found.)
Finally, set the database config found at your_rails_app/config/database:
# MySQL Production Database
production:
adapter: mysql
database: production
pool: 5
timeout: 5000
encoding: utf8
password: [your_root_password]
host: localhost
The rest, including the proxy setup and running as a Windows service, is covered at "How to install and configure Ruby on Rails with Windows Server 2008 EE". To make sure your basic Thin setup is running correctly:
thin start -p 3000 -e production
This should start your server on port 3000 in production mode using the MySQL database. The only thing missing here is load balancing, which I'm hoping to find an answer to soon!

Personally, I think the JRuby + Tomcat avenue is going to be your best bet, just because Tomcat is vetted on Windows and it along with JRuby are pretty stable. My first thought was Passenger as well, and it's sad that it's still not ported.

EngineYard is easy enough to deploy a rails app from a windows enviornment just install ey gem and change one or two things in your gemfile.lock a good link is https://support.cloud.engineyard.com/entries/20996706-Deploy-from-Windows
they give you 500 free hours as well when getting started

Related

Installing MaxMind GeoIP ruby library on heroku

I have a Rails app running on heroku. Now I want to run a rake task (which uses a model of my rails app) and geo-tag each record using the MaxMind GeoIP database (http://www.maxmind.com/app/geolite).
Using this database in a Ruby application involves :
Building it's C-API (http://www.maxmind.com/app/c) and then
Build the Ruby bindings for that (http://www.maxmind.com/app/ruby).
I could do this on my local machine and successfully get the country codes from IP addresses. However I do not know how to install these libraries on Heroku. From what I understand the ruby bindings are not available as a gem with native extensions (which heroku would have handled just fine). Also their C-API seems to have a few other dependencies which makes me wonder whether such a thing is possible at all.
So has anyone installed the MaxMind GeoIP (a.k.a Net::GeoIP) on Heroku? If yes how?
I could run the rake task from my laptop by pointing my local setup to the production DB. Before that I would like to know if I can run it from my Heroku setup itself to avoid latency or connection breakdown etc.
I found a gem which bundles the MaxMind C-API and provides it's own Ruby API. It works just fine - http://rubygems.org/gems/geoip
I ll tentatively accept this as the answer. However it would be awesome if someone can tell me how to install binary extensions to Ruby on Heroku.

Create stand-alone system services in Ruby

I want to build application which servers as a stand-alone system service, always run on the backend and servers a front-end with a web interface.
Like we do in Linux /etc/init.d/apache2 start , Same as I want to server my application /etc/init.d/myapp start.
My major target is to deliver on Linux specially Ubuntu, whole app would be in plain Ruby and front-end would be in Sinatra.
I want to make it install with simple, gem install my_app and command line features get available to start the service. The application would be doing heavily processing and database insertion. And I want that its configurations must be set as in pure linux fashion, like /etc/apache2/apache2.conf
Can any one guide me in it? Also if possible, i want to secure the code, is there any possibilities for it?
I am using the Daemon-Kit gem for the same requirements. Works very well in production. The only thing it does not include is the configuration with a .conf file, but it's easy to do it yourself with Ruby code. You can deploy with Capistrano, no need to install.

Heroku and Datamapper problems

I can launch a basic app on Heroku, displaying a message with get '/'... works just fine. However, whenever I try to add sqlite with datamapper, the thing breaks down.
In order to see my app structure, check out the project on github. I've kept the code pretty bare-bones.
In the log from heroku I'm getting:
2011-06-26T21:28:36+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-postgres-adapter (LoadError)
The thing about this is that I'm not using postgres, so I'm confused why it is saying this.
"The thing about this is that I'm not using postgres, so I'm confused why it is saying this."
You're using Heroku, so you are using Postgresql.
In your app.rb you have this line:
DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/notes.db")
which I'm guessing you got from the Heroku database docs. This line basically says "check for the environment variable 'DATABASE_URL', and if it's set use it as the database url, otherwise use the Sqlite url". Running locally this environment variable won't be set, so you'll use the Sqlite url, but on Heroku this will be set to something like (see the page linked above):
postgres://username:password#hostname/database
Datamapper will see that this is a Postgresql url, and try to require the postgres adapter, which isn't installed so will result in the error that you see.
The best solution would be to install Postgresql locally, so that your development and production environments are as similar as possible. If you can't do this, or don't want to, you can specify the Sqlite adapter locally, and the Postgres adapter in production. It'll look something like this in your Gemfile:
group :development do
gem 'dm-sqlite-adapter'
end
group :production do
gem 'dm-postgres-adapter'
end
If you do this you'll need to tell Heroku to which groups to leave out when installing gems, see the Heroku Gem Bunder docs.
You are moving from sqlite to postgres-sql and thus you should include dm-postgres-adapter in your Gemfile (and install it ofcourse).
Heroku only supports a read-only file system (or at least only supports read-only operations for any files that you want to be persistent). Hence, you can't use SQLite on Heroku. Heroku only supports PostgreSQL as a database so you need to configure DataMapper to use PostgreSQL (see Yet Another Geek's answer).
I'd recommend installing PostgreSQL in your development environment if you're planning to deploy to Heroku. Every database is a little different and no ORM will protect you from the differences. A bit of searching for questions tagged heroku and postgresql should show some of the problems you'll have if you develop on top of one database but deploy on another.

Integrating Ruby on Windows WAMP server so I can run Ruby and PHP at same time?

I've been searching on this but haven't found anything decisive so far.. I already have a windows WAMP server up and running and am using it for my PHP apps, I want to be able to run some small ruby scripts (to interact with a library that is not available in PHP), I don't even need Rails at this point, I just want to run ruby scripts and be able to run them from within a web browser type environment (like PHP) but I can't figure out how to do this since the "instant rails" takes the same resources of php and apache so it can't run at the same time unless I change the port but I'd rather just make it so it runs off the same apache as my PHP apps ( I don't even need a database at this point as thats all handled in my php apps).. any advice is appreciated
Seeing that you have accepted the answer from your other question: you won't be able to run a ruby TCP server on port X and Apache on the same port.
On the other hand if you decide to use Rails: Install InstantRails but don't start it. Copy the portion of Apache config (in InstantRails directory) that binds rails to Apache and edit it to handle everything under (for eample) /rails then paste it into your Apache config that runs PHP. You may have to fiddle with paths (PATH variable). This way you'll have Apache running on port X, all *.php will go to your PHP interpreter and everything under (for example) /rails will go to Rails/Ruby

Running gem server in passenger

I'm running a few rails/rake apps in Apache/passenger and I want to add the documentation app served by gem server to these apps, so I can easily give it a special (sub)domain, like docs.example.org, so it's easily available for all members of our team and nobody has to start the server himself or remember port numbers (like 8808, the default gem server port).
I would recommend looking into bdoc instead of gem server, it allows the user to access all their gem docs without a server running at all. It would also be trivial to modify bdoc to output to a specific directory then you could easily add a step to regenerate the docs.
The nice thing about having them in static files would be the apache config is dead simple.
If you do want to make bdoc output to a specific dir look at this line.
Edit:
I actually went ahead and branched this on github and made the change. Now you can supply the output directory on the command line and it will generate the static rdoc pages for you.
I'm running http://gems.local on my machine in case I want to do some Ruby cracking offline. (Plain journey, trains, etc).
This is really easy, you can actually run passenger with all the Ruby gems' documentation locally without having to access the net.
I was following Jason's tips and got everything working. See the following article and you should be ready to go:
http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs
Attila
I wrote a blog post on how I have my gems, ruby, rails and jquery docs locally using the yard server and nginx for proxing in mac os x. Steps for linux are almost the same, only thing that changes is the way to configure the daemons.
https://makarius.posterous.com/offline-rails-ruby-jquery-and-gems-docs-with

Resources