I'm creating a website based on Django with Docker. I've a problem whit the management of log files of Gunicorn. With the script below the site runs without problems:
#!/usr/bin/env bash
cd personal_website
exec gunicorn personal_website.wsgi:application \
--name personal_website \
--bind 0.0.0.0:"${PROJECT_PORT}" \
--workers 3 \
"$@"
Here what I see on terminal:
dev_website | [2022-01-21 16:36:17 +0000] [1] [INFO] Starting gunicorn 20.1.0
dev_website | [2022-01-21 16:36:17 +0000] [1] [DEBUG] Arbiter booted
dev_website | [2022-01-21 16:36:17 +0000] [1] [INFO] Listening at: http://0.0.0.0:8301 (1)
dev_website | [2022-01-21 16:36:17 +0000] [1] [INFO] Using worker: sync
dev_website | [2022-01-21 16:36:17 +0000] [11] [INFO] Booting worker with pid: 11
dev_website | [2022-01-21 16:36:17 +0000] [12] [INFO] Booting worker with pid: 12
dev_website | [2022-01-21 16:36:17 +0000] [13] [INFO] Booting worker with pid: 13
dev_website | [2022-01-21 16:36:17 +0000] [1] [DEBUG] 3 workers
But when I add the logging files:
#!/usr/bin/env bash
# Prepare log files and start outputting logs to stdout
touch ./logs/gunicorn.log
touch ./logs/gunicorn-access.log
cd personal_website
exec gunicorn personal_website.wsgi:application \
--name personal_website \
--bind 0.0.0.0:"${PROJECT_PORT}" \
--workers 3 \
--log-level=debug \
--error-logfile=./logs/gunicorn.log \
--access-logfile=./logs/gunicorn-access.log \
"$@"
I see the error below:
dev_website | Error: Error: './logs/gunicorn.log' isn't writable [FileNotFoundError(2, 'No such file or directory')]
And the site can't runs. Where is the mistake? I can see both files into the project volume.
Problem it was that I'm searching logs files into wrong folder.
#!/usr/bin/env bash
# Prepare log files and start outputting logs to stdout
touch ./logs/gunicorn.log
touch ./logs/gunicorn-access.log
cd personal_website
exec gunicorn personal_website.wsgi:application \
--name personal_website \
--bind 0.0.0.0:"${PROJECT_PORT}" \
--workers 3 \
--log-level=debug \
--error-logfile=../logs/gunicorn.log \
--access-logfile=../logs/gunicorn-access.log \
"$@"