I am developing a Rails v2.3 app. with MySQL v5.1 database on a Ubuntu machine.
I know the commands to start, stop Nginx and MySQL on command line.
But now, I need to have the following process defined in one of my rake task of my Rails app.:
stop Nginx --> stop(shut down) MySQL --> ... --> start MySQL --> start Nginx
Which means all these need to be defined in ruby script in a rake task of my Rails app.
I am not sure how to make ruby code run the above process(execute the commands) in my rake task?
Check out Ruby’s Kernel module (it’s built in). Using backticks, you can run the commands to stop/start nginx and MySQL, and even check their exit codes to make sure they executed properly (If your stop/start scripts support exit codes).
Example:
Substitute in your own stop/start commands in the backticks.
You can then run these tasks with
rake servers:stopandrake servers:start.