Created
December 18, 2012 14:10
-
-
Save hiroyuki-sato/4328270 to your computer and use it in GitHub Desktop.
Capistrano Executing a command as root without using sudo To avoid the error standard in must be a tty. Thank you Simone Carletti. http://www.simonecarletti.com/blog/2010/07/capistrano-executing-a-command-as-root-without-using-sudo/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# copy from | |
# http://www.simonecarletti.com/blog/2010/07/capistrano-executing-a-command-as-root-without-using-sudo/ | |
# | |
def surun(command) | |
# To avoid the error 'standard in must be a tty' | |
default_run_options[:pty] = true | |
password = fetch(:root_password, Capistrano::CLI.password_prompt("root password: ")) | |
run("su - -c '#{command}'") do |channel, stream, output| | |
channel.send_data("#{password}\n") | |
# | |
# please comment three lines if you don't need output result. | |
# | |
# if stream == :out | |
# puts output | |
# end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment