Search code examples
rubycapistranocapistrano3

Capistrano 3: "find ... -exec ..." command syntax in task


I am trying to integrate this shell command into a Capistrano 3 after deploy task:

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

However, I am failing at the proper Ruby syntax. I have tried most conceivable combinations between:

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

and

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

but invariably end up with the error: find: missing argument to -exec

Could anyone please help me with the proper way to separate the arguments of this command?


Solution

  • You are using wrong commands, :find is for using ruby functions, but you want to use find of linux utilities. Please try following

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

    Don't forget in the last I have double slashes to terminate command. But there is more good way to do it using following commands

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

    I was using it in my very old project like following

    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"]
    

    I think don't set permission of everything is really good idea, but when I did first time I was also getting confused so long time ago I have used following task which will go throughly and change all permission as you wanted

    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
    
    

    It has many things you remove and try what you want to do. Please note these are very old code, even I don't remember what are they doing, as I am not using capistrano any more to deploy but mostly dockers.