Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6855845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:48:35+00:00 2026-05-27T01:48:35+00:00

I am developing Rails v2.3 app. and using MySQL v5.1 on Ubuntu machine. I

  • 0

I am developing Rails v2.3 app. and using MySQL v5.1 on Ubuntu machine.

I have a rake task to stop and start mysql database like 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 get executed. However, because of this sudo , when I run the rake task, there will be a prompt ask me to input root password though the rake task get run successfully.

I want to avoid the password input thing, so I thought I could execute shell command to firstly change to root user, then stop/start MySQL, so I changed my code to 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 sudo su command to be run firstly. Now I run my rake task again, but, suprisingly the rake task run until exec 'sudo su' then it stopped, the rest code does not even get run. Why? How to get rid of it?

(Generally, I do not want to input root password during the rake task running for MySQL start and stop)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:48:35+00:00Added an answer on May 27, 2026 at 1:48 am

    You have several problems.

    First, the Kernel#exec method won’t return. See the API description:

    Replaces the current process by running the given external command.

    Second, it’s really weird to execute sudo from Ruby. Could you simply execute sudo rake db:some_db_task?

    UPDATED

    Third, Kernel#exec won’t return, but Kernel#system will. If you really want to sudo in your rake script, you need to use Kernel#system and execute sudo in every command. Ex:

       system 'sudo /etc/init.d/mysql stop'
       system 'sudo /etc/init.d/mysql start'
    

    system 'sudo su' doesn’t work. It will start a shell with root user, and when you leave the shell, the Ruby process won’t gain root permission.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MySQL v5.1. I am developing a Rails app. and writing a
I have started developing a new Rails app on my server using RVM, Rails
I have a Rails 3 app I'm developing with a team using Git/Github and
I'm developing a Rails 3 app on Ubuntu 11.04, and I get the following
i am developing a app and have been for a while using Rails 2.3.4
I am developing Rails v2.3 app. and using MySQL v5.1 . I need to
I am developing an app using Rails and jQuery. I would like to submit
I am developing a web app (using rails) that I will be launching within
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I am currently developing a Rails application using a database that was designed before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.