我做了下面一个小的测试任务:
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
从这篇文章 ,虽然它并不能帮助我... :(
可能有人请告诉我有前途的方法Capistrano的切换到root后运行命令?
提前致谢。
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