skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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 
    "$@"
    

  2. In your bash script, you first touch (create) the log files, then change the working directory. When you start the web server, the files are not located relative to the current working directory.

    In other words, first run your cd command and only then 2x touch commands.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search