aptible / supercronic

Cron for containers
MIT License
1.91k stars 115 forks source link

Logging of messages in console not related to cronjobs #100

Closed allinws closed 7 months ago

allinws commented 2 years ago

I'm running supercronic with Django, Docker and Supervisord, it works fine, however it logs thing not related to the cronjob, for example it's logging different error messages (from dotenv for example) and a print "LOGIN" which I do inside my Django app:

q_cron | crontab | time="2022-01-25T13:04:00Z" level=info msg=" dotenv.read_dotenv()" channel=stderr iteration=0 job.command=/var/app/bin/staging/count_number_of_users.sh job.position=0 job.schedule="* * * * *" q_cron | crontab | time="2022-01-25T13:04:03Z" level=info msg=LOGIN channel=stdout iteration=0 job.command=/var/app/bin/staging/count_number_of_users.sh job.position=0 job.schedule="* * * * *" q_cron | crontab | time="2022-01-25T13:04:04Z" level=info msg="Number of users in the DB: 68" channel=stdout iteration=0 job.command=/var/app/bin/staging/count_number_of_users.sh job.position=0 job.schedule="* * * * *" q_cron | crontab | time="2022-01-25T13:04:05Z" level=info msg="job succeeded" iteration=0 job.command=/var/app/bin/staging/count_number_of_users.sh job.position=0 job.schedule="* * * * *"

This is the part of my Dockerfile where I install Supercronic

# SUPERCRONIC (CRON-TABS)
#########################

ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-amd64 \
    SUPERCRONIC=supercronic-linux-amd64 \
    SUPERCRONIC_SHA1SUM=048b95b48b708983effb2e5c935a1ef8483d9e3e

RUN curl -fsSLO "$SUPERCRONIC_URL" \
 && echo "${SUPERCRONIC_SHA1SUM}  ${SUPERCRONIC}" | sha1sum -c - \
 && chmod +x "$SUPERCRONIC" \
 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic`??```

This is how I use it in Supervisord
```[program:crontab]
user=www-data
command=/usr/local/bin/prefix-log /var/app/bin/staging/crontab.sh
directory=./projectile/
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile = /dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile = /dev/fd/2
stderr_logfile_maxbytes=0```

**Where I run it (crontab.sh)**

```supercronic /var/app/bin/staging/crontab 
allinws commented 2 years ago

I can confirm that also running it from a regular docker-compose container I still get logging messages that are not related to the cronjob but happen to be in the STDOUT when the cron job executes.... Any idea on how to fix this?

scheduler_1 | time="2022-01-27T16:37:59Z" level=info msg=starting iteration=0 job.command="python3 /home/kontorshund/web/manage.py count_users" job.position=0 job.schedule="* * * * *" scheduler_1 | time="2022-01-27T16:38:00Z" level=info msg="Not using S3" channel=stdout iteration=0 job.command="python3 /home/kontorshund/web/manage.py count_users" job.position=0 job.schedule="* * * * *" scheduler_1 | time="2022-01-27T16:38:00Z" level=info msg="Using live email settings" channel=stdout iteration=0 job.command="python3 /home/kontorshund/web/manage.py count_users" job.position=0 job.schedule="* * * * *" scheduler_1 | time="2022-01-27T16:38:01Z" level=info msg="Number of advertisements: 14" channel=stdout iteration=0 job.command="python3 /home/kontorshund/web/manage.py count_users" job.position=0 job.schedule="* * * * *" scheduler_1 | time="2022-01-27T16:38:02Z" level=info msg="job succeeded" iteration=0 job.command="python3 /home/kontorshund/web/manage.py count_users" job.position=0 job.schedule="* * * * *"

UserNotFound commented 7 months ago

Hi @allinws, supercronic isn't designed to run outside of a container or under a process manager. If you can provide a Dockerfile or container that exhibits the issue we might be able to examine how supervisor and Django are interacting with it.

Otherwise, our advice would be to run supercronic in its own container, since this is an anti-pattern.