Search code examples
ruby-on-railsspreedigital-oceancloud66

Rails Cache Permission Error


I have a Rails app (a Spree Commerce store) running on Digital Ocean and deployed through Cloud 66.

I would like to SSH into my server, run a rails console, and adjust some Spree config settings. When I try to do this I get a permissions error:

Errno::EACCES: Permission denied @ dir_s_mkdir - /var/deploy/my-app/web_head/releases/20150220220517/tmp/cache/29B

According to the Spree Developer Guide's page on preferences, this is because preferences are cached into memory to improve performance. The problem (I think) is that my user doesn't have write access to the tmp/cache directory, and it is my user that is running the rails console.

If I ls -l on the $STACK_PATH/tmp/cache directory I get the following:

> lrwxrwxrwx 1 nginx nginx 43 Feb 20 22:05
> tmp/cache ->
> /var/deploy/my-app/web_head/shared/cache

I figure I need to give my user write access to the directory, like the nginx user has. I tried adding myself to the nginx user group, but that didn't seem to have any effect. What can I do to prevent this permissions error?


Solution

  • Ok, I figured it out based on this question and answer on Cloud 66's support forum.

    I changed the group owner of the cache folder to app_writers, a group that my user is a part of. The Cloud 66 way to do this is with a deploy hook. Here's the yml file that worked for me:

    production:
        after_rails:
            command: chown nginx:app_writers /var/deploy/my-app/web_head/current/tmp/cache && chmod -R 775 /var/deploy/my-app/web_head/current/tmp/cache
            target: rails
            run_on: all_servers
            sudo: true