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

Checking for creation of logfile, without CPU spin, but bail if too many errors #113

Merged
merged 2 commits into from
May 8, 2018

Conversation

sychan
Copy link
Contributor

@sychan sychan commented May 7, 2018

Commit 4c86ed7 fixed the CPU spinning issue, but it also causes dockerize to bail out immediately if a logfile hasn't been created yet by the program to be run when the tail thread goes to look for it. This race condition has broken a lot of my images built using dockerize, and I imagine that it may effect others.

This PR uses time.Sleep() to have the tail thread sleep 2 seconds before retrying, and allows a certain number of retries before bailing out. The number of retries is set for 30, which is gives about a minute for a program to initialize and get its logs going - I'm happy to set it lower if a minute seems too long.

Tailing named pipes is still supported, but the code assumes that if this is a named pipe, mkfifo has already been called before dockerize gets executed.

@jwilder jwilder merged commit 137d5c8 into jwilder:master May 8, 2018
@jwilder
Copy link
Owner

jwilder commented May 8, 2018

Thanks @sychan!

@apollo13
Copy link

Hi @sychan. when I run your changes from master (since this is not in a released version yet); I do get:

2018/12/30 13:22:20 Warning: unable to stat /var/log/nginx/error.log: stat /var/log/nginx/error.log: no such file or directory
2018/12/30 13:22:20 Warning: unable to stat /var/log/nginx/access.log: stat /var/log/nginx/access.log: no such file or directory
2018/12/30 13:22:27 Warning: unable to tail /var/log/nginx/error.log: tomb: still alive
2018/12/30 13:22:29 Warning: unable to tail /var/log/nginx/error.log: tomb: still alive
2018/12/30 13:22:31 Warning: unable to tail /var/log/nginx/error.log: tomb: still alive
2018/12/30 13:22:36 Warning: unable to tail /var/log/nginx/error.log: tomb: still alive
2018/12/30 13:22:40 Warning: unable to tail /var/log/nginx/error.log: tomb: still alive
2018/12/30 13:22:42 Warning: unable to tail /var/log/nginx/error.log: tomb: still alive

The first two lines do make sense, the logfiles are not there yet, but it looks as if it runs into another error afterwards. For reference I am using this dockerfile https://github.com/jwilder/dockerize/blob/b6062ae239adee8b2e7fa464ceaea1721fdd1ccb/examples/nginx/Dockerfile with /var/log/nginx/* cleared… do you have any ideas?

@apollo13
Copy link

Or even another issue, I use this dockerfile:

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y nginx
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN rm /var/log/nginx/*
EXPOSE 80
CMD ["dockerize", "-stdout", "/var/log/nginx/access.log", "-stderr", "/var/log/nginx/error.log", "nginx"]

and run with:

docker run --rm -v /home/florian/go/bin/:/usr/local/bin -p 8080:80 test2

where I map my go path in so I do get the local dockerize version, I get no output at all aside from:

2018/12/30 13:29:48 Warning: unable to stat /var/log/nginx/error.log: stat /var/log/nginx/error.log: no such file or directory
2018/12/30 13:29:48 Warning: unable to stat /var/log/nginx/access.log: stat /var/log/nginx/access.log: no such file or directory

once.

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

Successfully merging this pull request may close these issues.

None yet

3 participants