开发者

Start up required additional services (resque, redis) with `rails server` command

I would like my development environment for Rails to automatically start redis and resque (and potentially in other projects, mongod, mysql-server etc.) for me, in the following cases:

  • When starting up the development server rails server.

Additionally, it would be nice if the following cases detect already running services, and, if not running start them up too:

  • Rake rspec, rspec /spec, when running tests.
  • When starting up a rails console.

When shutting down the rails server, the started child-services should be shut down too.

What is the correct place for such additional startup scripts?

And how to avoid them being star开发者_如何学编程ted in production too (where I run everything trough /etc/init.d services)?


A lot of these built-in tasks are available as rake tasks already.

You can create a master rake task that does it all.

For example, with resque, you get "rake resque:start" "rake resque:scheduler:start", etc.

You can create a generic "start" task that depends on the rest. Similarly, a "stop" task would shut everything down.

So you would do:

rake start # starts all associated processes
rake stop  # stops them all

This is also very use to use from Capistrano, when you end up deploying your code somewhere else. Rake tasks are very easy to call from Capistrano.


I think it's really better to do that in some external script. Do it in your rails server command can be really annoying to anyone to try your code.

By example, in one year, a nez developper come to your project. He can be desoriented if your rails server commande launch a such of other application in background.

In same idea, if you do that you need maintain your code in your rails env. Can be a little tricky. Maintain an independant script can be more usefull.

You can add your script in script directory. That be a good pratice. But not when you launch a command with a manual who do not that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜