简体   繁体   English

capistrano使用sudo运行内部命令

[英]capistrano run internal command using sudo

Our capistrano setup is: ssh with regular user, but deploy to a location requiring sudo permissions to create files. 我们的capistrano设置是:普通用户使用ssh,但是部署到需要sudo权限才能创建文件的位置。

I want to run the specific capistrano command run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}" using sudo. 我想运行特定的capistrano命令,使用sudo run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}" Is there a neat way to over ride it? 有没有一种整洁的方法可以骑行呢?

def distribute!
  upload(filename, remote_filename)
  run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
end

I believe you can use the "sudo" function inside capistrano eg 我相信您可以在capistrano中使用“ sudo”功能,例如

def distribute!
  upload(filename, remote_filename)
  sudo "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
end

The following workaround made it work. 以下变通办法使其正常工作。

task :self_own_dirs do
  sudo "chown -R #{user} #{releases_path}/.."
end

before 'deploy:update_code', 'deploy:self_own_dirs'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM