Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 started in production too (where I run everything trough /etc/init.d services)?

like image 506
berkes Avatar asked Dec 10 '25 13:12

berkes


1 Answers

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.

like image 56
kigster Avatar answered Dec 12 '25 02:12

kigster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!