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 started 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:
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.