简体   繁体   English

Ruby on Rails应用程序缓存权限capistrano的部署

[英]Deployment of Ruby on rails application cache permission capistrano

I have deployed application using Capistrano and Passenger, I did not played with permission it is all root user doing stuff. 我已经使用Capistrano和Passenger部署了应用程序,但没有获得许可,这是所有root用户在做的事情。

I have installed NGINx and passenger, everything working fine, when I deploy my application it goes smoothly and all setup. 我已经安装了NGINx和passenger,一切运行正常,当我部署应用程序时,它运行顺利且所有设置都已完成。 But when I browse it gives me error that I have permission issue for cache directory. 但是,当我浏览它时,出现错误,提示我具有缓存目录的权限问题。

So each time when I deploy I have to give this permission again and again. 因此,每次部署时,我必须一次又一次地授予此权限。 Following is my Cap configuration 以下是我的帽子配置

lock "~> 3.11.1"
set :application, "my_app_ame"
set :repo_url, "git@github.com:url_of_git.git"

set :passenger_restart_with_touch, true
set :deploy_to, "/var/www/rubysites/test_production"
append :linked_files, "config/credentials.yml.enc"
append :linked_files, "config/master.key"
append :linked_files, "config/database.yml"

and my staging.rb file 和我的staging.rb文件

set :stage, :staging
set :rails_env, :production
set :branch, "development"

server "ror.test_domain.com", user: "root", roles: %w{app db web}

But on each deploy I have to run command to change permissions 但是在每次部署时,我必须运行命令来更改权限

 chmod -R 777 releases/

Got no response, but I have tried few things. 没有回应,但我尝试了一些事情。 1. I have added following gem in my Gemfile 1.我在Gemfile中添加了以下gem

gem 'capistrano-file-permissions'

and than I added following in my Capfile 然后我在Capfile中添加了以下内容

set :file_permissions_paths, ["app/logs", "app/cache"]
set :file_permissions_users, ["www-data"]

Unfortunately it did not work for me, I think I have incorrect understanding of files where to put these commands. 不幸的是,它对我不起作用,我认为我对将这些命令放在哪里的文件有不正确的理解。

  1. I used another idea where I run execute command to do file permissions. 我使用了另一个想法,我在其中运行execute命令来执行文件权限。 so I added following my deploy.rb file. 所以我添加了我的deploy.rb文件。 I also added some rake tasks as I have to do that for some updates. 我还添加了一些rake任务,因为我必须进行一些更新。
namespace :deploy do
  task :check_permissions do
    on roles(:web) do
      execute "chmod -R 0777 #{release_path}"
      execute "echo 'finished'"
      execute "cd #{deploy_to}/current && /usr/bin/env rake countries:update RAILS_ENV=production"
    end
  end
end

Voila it worked for me, and now all good, but yes I have some shortcoming on knowledge about cap files, so hope in future I will be able to improve it. 瞧,它对我有用,现在一切都很好,但是是的,我在有关封顶文件的知识上有一些缺点,因此希望将来我能够改进它。

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

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