Capistrano 3:任务

问题描述

我正在尝试在部署任务后将此 shell 命令集成到 Capistrano 3 中:

find /var/www/mysite/somepath/ -type d -exec chmod 775 {} \;

但是,我在正确的 Ruby 语法上失败了。我尝试了以下最可能的组合:

execute :find,"#{deploy_to}/somepath/ -type d -exec chmod 775 {} \;"

execute :find,"#{deploy_to}/somepath/","-type d","-exec","chmod","755","{}",";"

但总是以错误告终:find: missing argument to -exec

谁能帮我用正确的方法来分隔这个命令的参数?

解决方法

您使用了错误的命令,:find 用于使用 ruby​​ 函数,但您想使用 find 的 linux 实用程序。请尝试以下

execute "find /var/www/mysite/somepath/ -type d -exec chmod 775 {} \\;"

不要忘记在最后我有双斜线来终止命令。但是使用以下命令还有更好的方法

set :file_permissions_paths,["app/logs","app/cache"]

我在我的旧项目中使用它,如下所示

set :permission_method,:chmod
set :use_set_permissions,true
set :writable_dirs,["app/cache","app/logs"]
set :file_permissions_paths,["app/log","app/cache","storage"]

我认为不要设置所有权限真的是个好主意,但是当我第一次这样做时,很久以前我也感到困惑,我使用了以下任务,该任务将彻底完成并根据需要更改所有权限>

namespace :deploy do
  task :check_permissions do
    on roles(:web) do
      execute "chmod -R 0777 #{release_path}"
      execute "echo 'finished'"
      execute " /bin/systemctl restart nginx"
      #execute "cd #{deploy_to}/current && /usr/bin/env rake countries:update RAILS_ENV=production"
    end
  end
end

您可以删除许多内容并尝试自己想做的事情。请注意这些是非常旧的代码,即使我不记得它们在做什么,因为我不再使用 capistrano 进行部署,而是主要使用 docker。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...