I am developing a Rails v2.3 application. and using MySQL v5.1 on an Ubuntu machine.
I have a rake task to stop and start the mysql database, for example the following:
namespace :db do task :some_db_task => :environment do ... exec 'sudo /etc/init.d/mysql stop' ... exec 'sudo /etc/init.d/mysql start' end end
As you see above in the code, I used sudo
to make sure the command is complete. However, because of this, sudo
, when I run the rake task , I will be prompted for the root password , although the rake task will run successfully.
I want to avoid entering a password, so I thought I could run a shell command to switch to root user first and then stop / start MySQL, so I changed my code to the following:
namespace :db do task :some_db_task => :environment do ... exec 'sudo su' exec '/etc/init.d/mysql stop' ... exec '/etc/init.d/mysql start' end end
See, I added the sudo su
command to start over. Now I run my rake command again , but by the way, the rake task starts before exec 'sudo su'
, after which it stops , the rest of the codes do not even start. What for? How to get rid of it?
(As a rule, I do not want to enter the root password during the execution of the rake task to start and stop MySQL)
source share