monicahq / monica

Personal CRM. Remember everything about your friends, family and business relationships.
https://beta.monicahq.com
GNU Affero General Public License v3.0
21.45k stars 2.14k forks source link

Redirect output of docker cron to stdout #2663

Closed asbiin closed 4 years ago

Brice187 commented 5 years ago

Could you please specify this issue? i know some docker :)

asbiin commented 5 years ago

Currently the only logs shown on docker logs comes from apache output. I would like to output the logs from the 'cron' task on the docker logs too. I tried with redirecting the output on /dev/stdout but it's not working.

pzl commented 4 years ago

So docker logs are listening to the stdout of process pid 1 in the container. Since that's what docker is primarily "executing" (even though other things can run in the container namespace, like cron). This is the important part. PID 1

When cron runs, it might be pid 5 or 7 or something. So writing to /dev/stdout from the cron process perspective, will be a symlink to it's own process's stdout. Same as just normally printing to stdout with > or echo or anything else. Here's a quick exercise to demonstrate:

$ ls -la /dev/stdout
lrwxrwxrwx 1 root root 15 Oct 18 21:52 /dev/stdout -> /proc/self/fd/1

We can see this goes to /proc/self/fd/1. Where the 1 here is not about PIDs, but rather that stdout is file descriptor number 1 (stdin is 0, stdout is 1, stderr is 2).

But /proc/self itself, is a symlinked directory.

$ ls -la /proc/self
lrwxrwxrwx 1 root root 0 Oct 18 21:52 /proc/self -> 306584

so /dev/stdout is really pointing to /proc/306584/fd/1, your current process's stdout (so for cron, cron's already existing stdout).

Docker is listening to /proc/1/fd/1 so you're welcome to print right to that.

asbiin commented 4 years ago

Thanks @pzl ! I was able to fix this in #3129

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.