Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails Error: Unable to access log file. #110

Closed
kswope opened this issue Oct 11, 2015 · 7 comments
Closed

Rails Error: Unable to access log file. #110

kswope opened this issue Oct 11, 2015 · 7 comments

Comments

@kswope
Copy link

kswope commented Oct 11, 2015

I don't know why rails/passenger is creating a root owned log production.log file. Using this container is the first time I've seen this.

Actually I wont be logging to production, I'm using the 12factor gem, but it looks like an unwritable production log screws up the process before anything can log to stdout and it all ends up in stdout.
Not using the 12factor gem gets me the same results so its not that. [EDIT] The 12factor gem is rightfully logging to stdout. So really the only issue I have now is the error message about being unable to log to a file I wouldn't be logging to anyway, but its still annoying :)

App 81 stderr: Rails Error: Unable to access log file. Please ensure that /home/app/webapp/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /home/app/webapp/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
root@711ad2fe8c1d:/home/app/webapp# ll -d log/
drwxrwxr-x 2 app app 4096 Oct 10 23:57 log//
root@711ad2fe8c1d:/home/app/webapp# ll log
total 8
drwxrwxr-x  2 app  app  4096 Oct 10 23:57 ./
drwxr-xr-x 25 app  app  4096 Oct 10 23:57 ../
-rw-rw-r--  1 app  app     0 Oct 10 23:54 .keep
-rw-r--r--  1 root root    0 Oct 10 23:57 production.log
   server {                                                                                                                                          

       location ~ ^/assets/ {                                                                                                                        
         expires 1y;                                                                                                                                 
         add_header Cache-Control public;                                                                                                            
         add_header ETag "";                                                                                                                         
         break;                                                                                                                                      
       }                                                                                                                                             

       listen 80;                                                                                                                                    
       server_name myapp;                                                                                                                   
       root /home/app/webapp/public;                                                                                                                 

       passenger_enabled on;                                                                                                                         
       passenger_user app;                                                                                                                           

       passenger_ruby /usr/bin/ruby;                                                                                                                 

   }   





@FooBarWidget
Copy link
Member

Do you happen to run any rails rake commands from the dockerfile? If so, those commands are run as root and will create a root owned log file.

@kswope
Copy link
Author

kswope commented Oct 15, 2015

I've got

RUN chown -R app.app $rails_root
RUN RAILS_ENV=production rake assets:precompile

Looks like I just need to reverse the order of those RUNs and see what happens. If this is true how isn't everybody getting bitten by this?

@mech
Copy link

mech commented Oct 16, 2015

I have this issues also. In my Dockerfile I don't have any rake task RUNing. However, I do have the RUN whenever -w for cron job does that count?

@mech
Copy link

mech commented Oct 16, 2015

Should I need to change to USER before running whenever like this:

USER app
RUN whenever -w

Or it should be like this

RUN sudo -u app whenever -w

@FooBarWidget
Copy link
Member

passenger-docker (and baseimage-docker, on which it is based) provides the setuser tool for this which is better than both the USER stanza and sudo. Use it like this:

RUN setuser app rake asset:precompile RAILS_ENV=production

See the baseimage-docker documentation for more information about setuser.

@kswope
Copy link
Author

kswope commented Oct 16, 2015

I'm starting to wonder if just skip all the USER and setuser and just put this at the end

   RUN chown -R app.app $rails_root                                                                                                                  

I don't think it creates another image layer and because COPY is so dumb (always copies as root!, just found that out) you are going to need a chown in there anyway.

@przbadu
Copy link

przbadu commented Jul 21, 2016

That one line rake assets:precompile screwed me up. Man I did used chown, even used chmod -R 777 log/ and nothing worked. Previously it was fixed using sudo, but with latest release 0.9.19 I can't even use sudo.

And the fix was as @FooBarWidget suggested, we can use RUN setuser app instead of RUN sudo -u app. Thanks a lot.

@FooBarWidget: rake task should be assets:precompile, i saw you are using asset, and rest are working perfectly fine.

RUN setuser app rake assets:precompile RAILS_ENV=production

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants