Friday, April 29, 2011

Netbeans and Rails: Is there a way to make the Run option in netbeans also start thinking_sphinx?

I don't want to keep sphinx running all the time on my dev machine. I'd like a way to automatically execute rake thinking_sphinx:start when I run my app via netbeans. Is there a way to do this

[also - I am using Windows]

Thinking sphinx needs to run as a separate process.

From stackoverflow
  • You will need a third-party program called PsExec to do this. Otherwise you won't be able to start a background process using Ruby on Windows.

    First of all download PsExec here. Unpack (at least) psexec.exe and run it once manually - you have to agree to the license :-/.

    After that add the following line to script/server of your Rails app:

    system 'PATH_TO_PSEXEC/psexec -d rake.bat'
    

    Now you create the rake.bat with the commands to run in parallel to your server. Put the file with the following contents into your Rails app's root directory.

    rake thinking_sphinx:start
    

    This line should do the trick, but it may fail e.g. when NetBeans' JRuby version differs from Ruby installed on your host. Or if Ruby isn't installed at all. In that case you should call rake with the complete path of JRuby:

    "PATH_TO_NETBEANS/ruby2/jruby-1.2.0/bin/jruby" "PATH_TO_NETBEANS/ruby2/jruby-1.2.0/bin/rake" thinking_sphinx:start
    

    When you start the server now, an additional Windows command-line pops up with the running rake task.

    Needless to say that you shouldn't add the code to script/server on your production server.

0 comments:

Post a Comment