1

以下の小さなテストタスクを作成しました。

set :user, "user"
set :password, "password"
set :root_password, "root password"
set :use_sudo, false
role :srv, "exmaple.com"

task :show_info do
    run "iptables -L", :shell => "su -" do |channel, stream, data|
        channel.send_data("#{root_password}\n")
    end
end

このサーバーでは の使用が許可されていないためsudo、通常のユーザーとしてログインして root になる必要があります。

私もこの記事surunから作成しようとしましたが、役に立ちません... :(

カピストラーノでルートに切り替えた後にコマンドを実行する有望な方法を教えてください。

前もって感謝します。

PS出力ログを追加しました:

$ cap show_info
  * executing `show_info'
  * executing "iptables -L"
    servers: ["example.com"]
    [example.com] executing command
    command finished in 000ms
failed: "su - -c 'iptables -L'" on example.com
4

1 に答える 1

2

ポイントは default_run_options[:pty] = true

これを試して

def surun(command)
  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")
  end
end
于 2012-12-18T13:58:22.350 に答える