So i am developing and deploying Ruby on Rails applications on Windows. Recently i started experimenting with the newer versions of ruby (mingw32platform). One of the side-effects is that the mongrel-service, which i always used to deploy my rails-applications no longer works on mingw32. And aside of that, i have read on various instances [ref] that thin should be better (more efficient) than mongrel. But i still want to install it as a service. First off, you need to download and install the Windows Resource Kit. This contains the executables to make a service of any executable or script. Then create the service running (in the console): [bash] C:\Program Files\Windows Resource Kits\Tools> instsrv "[my_service_name]" "c:\program files\Windows Resource Kits\Tools\srvany.exe" The service was successfuly added! Make sure that you go into the Control Panel and use the Services applet to change the Account Name and Password that this newly installed service will use for its Security Context. [/bash] This will add an empty entry in the registry, which actually still does nothing. To get it working, we have to start regedit
, and navigate to the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services[my_service_name] Create a new key (folder) named Parameters
. This will contain the settings of our actual application that will be run as a service. Add the following String Values: [bash] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services[my_service_name]\Parameters] Application=c:\ruby\bin\ruby.exe AppDirectory=[my_ruby_app_folder] AppParameters=c:\ruby\bin\thin start -p 4000 -e production [/bash] Assuming that c:\ruby\bin is your ruby folder, and you want your thin to listen to port 4000. Once that is done, start the service, and your rails application should be up and running :)
Unfortunately, to do this on Windows 2008 you need to perform some extra steps. As you can't install the resource kit on Windows Server 2008R2 for some peculiar reason, and at the time of this posting, i have not found a Windows Server 2008 Resource Kit Tools, so i took the following steps:
And just today I discovered an update of mongrel_service was announced, so you can still work using mongrel_service instead of using thin and manually creating the service. What you need to do:
mongrel_rails service::install -N myapp -c c:\my\path\to\myapp -p 4000 -e production
That is much easier of course.
Comments
Hello, I'm struggling to find a way of deploying rails3/ruby192 apps on Windows. Your solution seems excellent but you don't specify the rails version you are using? Another question for you? Is it easy to compile thin on Windows or it's a headache? gem install thin doesn't look very good since it wants to build stuff which is always scary on Windods :D Thanks for your time, Gam
I used this solution both on ruby 1.8.7 and 1.9.2. Just make sure you get a ruby from the mingw32 platform (hhtp://rubyinstaller.com). If you install the developer kit (http://rubyinstaller.org/add-ons/devkit/) as well, installing a gem like thin will just work (and it will compile on the fly). So it actually is really easy. Good luck!
Hello, i use mongrel_service and mingw32 on production environment built on windows 2008 R2 64bit, it works.
Great article, Nathan! Thanks! I was able to get this working with Windows 2008 R2, Ruby 1.9.2 and Rails. Started serving with Webrick and switch to thin. I am also using Application Request Routing via IIS7 to balance/host. (http://www.iis.net/download/ApplicationRequestRouting) gamov, you can also install eventmachine easily by specifying a platform... just have a look at: gem list -r eventmachine ...you should get something like: eventmachine (0.12.10 ruby java x86-mswin32-60 ...) ...the list after the version is a list of available platforms... so: gem install eventmachine --platform=x86-mswin32-60 ...should fix you up. Thins is definitely worth the trouble.
UPDATE: I lied. The platform option installs a version of eventmachine linked against the 1.8, not the 1.9... so it works for 1.8 folks not the 1.9. Sorry, for the confusion there.
Glad the article was useful for you.
Very Helpful, Thank you!!!
How about the balance loading in thin with apache webserver? How can I configure apache to do this? Thanks in advance
I have a problem with thin server. I have created a service in windows and load well, but when I put the address in internet and I get an error The Page can't be displayed. If I do rails s -e production from command line is work perfectly. Could you help me?
Thank you Lourdes, for another question in the category: "please use your psychic skills to guess my problem". I could help you, with a little more information. Did you create the service as I described it? When the service is starting, do you see the production.log file being made, and if so: do you see any errors? If it is not starting: check the application folder in your service configuration. Do you start the service on port 4000 (as I suggested) and are you checking on port 4000? E.g. <code>http://localhost:4000</code>
Hello nathanvda. I have install windows 2008, I create the service as you described it, in port 4000. I create in regedit AppDirectory, Application and AppParameters. AppDirectory= C:\Sites\aplicaciones Application = C:\RailsInstaller\Ruby1.9.3\bin\ruby.exe AppParameters = C:\RailsInstaller\Ruby1.9.3\bin\thin start -p 4000 -e production. Service run correctly without errors. if I put http://localhost:4000 the error is This page can't be display If I run from command line rails s -p 4000 -e production is ok. In production.log I can't see any error. Thanks in advanced. Lourdes
My spanish is no good, but the c:\sites\aplicaciones is the rails folder? because it sounds like applications, and it should be the rails root folder. Otherwise I have no clue. Is the error you get a rails error (this page can't be displayed?). If so, the rails server is hit. Maybe proxy settings? Try running <code>thin start -p 4000 -e production</code> from the command line?
No, c:\sites\aplicaciones is my aplication. If I try thin start -p 4000 -e production from the command line, it gives me an error: You have alredy activated rack 1.5.2 but your gemfile requiere rack 1.4.5. Using bundle exect you may solve this. Sorry but before I used mongrel_service and I have update rails in a new server and I install rails 3.2.13, and mongrel_service doesn't work. Thanks
The mongrel_service will most likely have the same error. Easiest to update rake in your gemfile to the newest version? Or use <code>bundle exec</code>. Nice it is solved.
Hello nathanvda, how many services whith thin I can run? I have three ( ports 4000, 40001, 4002), but today I create other (4003), and the the threee frists doesn't work Thanks in advanced. Lourdes
There is normally no limitation, except for available memory and database connections (resources). Normally one extra would not be a problem, and even if it was, it would only be a problem for the one extra (if it is a lack of resources that is the cause of your problem). So I think you have another problem :)
Got an error 'http://localhost:4000' while using using thin server as a service with Rails 3. My production.log file shows the text "Connecting to database specified by database.yml". Any help would be appreciated. Thanks
Hi Lokendra: that is not really an error? :) My guess: have you checked the <code>production</code> entry in your `database.yml` ? It seems like it is trying to connect and does not find the database? If that does not solve it: check stackoverflow.com and/or ask your question there. You will need to provide a little more background, because you provide very little information here.
Hi Nathanvda, Thanks for the quick response. Actually the same database details works when I run thin server from command prompt, but through service I got error. And my database.yml file contains information: production: adapter: sqlserver dsn: DSN_Name # created System DSN mode: odbc database: Database_Name username: sa password: passwd host: 127.0.0.1
Do you run thin server from command prompt in production mode? Please note, like I said, that stackoverflow is a better forum for such questions :)
Hello, I install ruby193, now I want to create windows service for redmine via mongrel service, but when I write the command mongrel_rails service::install -N RedMine -c d:RailsInstaller\sites\redmine(this is the path for redmine) -p 3000 -e production, it shows an error as below: d:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb: 36:in `require': 126: The specified module could not be found. - d:/RailsInsta ller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5-x86-mingw32/lib/http11.so (LoadError) from d:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custo m_require.rb:36:in `require' from d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5- x86-mingw32/lib/mongrel.rb:12:in `' from d:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custo m_require.rb:36:in `require' from d:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custo m_require.rb:36:in `require' from d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5- x86-mingw32/bin/mongrel_rails:11:in `' from d:/RailsInstaller/Ruby1.9.3/bin/mongrel_rails:23:in `load' from d:/RailsInstaller/Ruby1.9.3/bin/mongrel_rails:23:in `' I am new for redmine, ruby, and mongrel, so can anybody help me on this ? Thank you.
Can you ask this question on stackoverflow, and post the link here? Please note that mongrel_rails is no longer at this moment, so you better use thin.
Hi, I realise I'm posting this late but everything is working fine on Windows 7 but when I run the service it runs but no sign of thin server running, i.e. no logs being created. I'm wondering could you give me more info on how to create the String Values, might be doing this wrong. Thanks, Dan
I am using the same approach and I don't see any logs either. I am trying to debug a issue and have no clue now.
My best guess: did you try running <pre>rails s -p 4000 -e production</pre> on the command-line? (as mentioned before).Running a rails app in production is something different: it will connect to a different database entry, and it will pre-load all code, meaning any error (even in unused code) will block starting your rails process.
Add comment