diff --git a/.gitignore b/.gitignore index e172ada..3da5557 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ __pycache__/ old_app/ .env* /static +gunicorn.access.log +gunicorn.error.log diff --git a/Pipfile b/Pipfile index 7bd0014..5d3347f 100644 --- a/Pipfile +++ b/Pipfile @@ -11,6 +11,7 @@ django = "*" django-allauth = "*" python-dotenv = "*" gunicorn = "*" +psycopg = "*" [requires] python_version = "3.12" diff --git a/Pipfile.lock b/Pipfile.lock index 4f208df..432f1f9 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "56952c337cbb1cb5f9a3ef896a18313b33a55d7a125de845ebba7d9dbc7a7db3" + "sha256": "237f489e87c4f9e74c0476a54adb490a62f07e806fd9ade27513a2792e515f70" }, "pipfile-spec": 6, "requires": { @@ -58,6 +58,15 @@ "markers": "python_version >= '3.8'", "version": "==24.1" }, + "psycopg": { + "hashes": [ + "sha256:644d3973fe26908c73d4be746074f6e5224b03c1101d302d9a53bf565ad64907", + "sha256:a5764f67c27bec8bfac85764d23c534af2c27b893550377e37ce59c12aac47a2" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==3.2.3" + }, "python-dotenv": { "hashes": [ "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca", @@ -74,6 +83,14 @@ ], "markers": "python_version >= '3.8'", "version": "==0.5.1" + }, + "typing-extensions": { + "hashes": [ + "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", + "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8" + ], + "markers": "python_version < '3.13'", + "version": "==4.12.2" } }, "develop": { diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..c8f6828 --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,10 @@ +bind = "unix:/run/gunicorn.sock" +workers = 3 + +accesslog = "gunicorn.access.log" +errorlog = "gunicorn.error.log" + +# Whether to send Django output to the error log +capture_output = True +# How verbose the Gunicorn error logs should be (debug, info, warning, error, critical) +loglevel = "info" diff --git a/itacpc/settings.py b/itacpc/settings.py index 66639b3..0568899 100644 --- a/itacpc/settings.py +++ b/itacpc/settings.py @@ -196,4 +196,33 @@ SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True ALLOWED_HOSTS = ['teams24.itacpc.it', 'localhost'] - STATIC_ROOT = BASE_DIR / 'static/' + STATIC_ROOT = '/var/www/django/static/' + LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "root": {"level": "INFO", "handlers": ["file"]}, + "handlers": { + "file": { + "level": "INFO", + "class": "logging.FileHandler", + "filename": "/var/log/django.log", + "formatter": "app", + }, + }, + "loggers": { + "django": { + "handlers": ["file"], + "level": "INFO", + "propagate": True + }, + }, + "formatters": { + "app": { + "format": ( + u"%(asctime)s [%(levelname)-8s] " + "(%(module)s.%(funcName)s) %(message)s" + ), + "datefmt": "%Y-%m-%d %H:%M:%S", + }, + }, + } diff --git a/systemd/gunicorn.service b/systemd/gunicorn.service index 35ebc76..9141f04 100644 --- a/systemd/gunicorn.service +++ b/systemd/gunicorn.service @@ -8,9 +8,7 @@ User=itacpc Group=www-data WorkingDirectory=/home/itacpc/teams ExecStart=/home/itacpc/.local/share/virtualenvs/teams-_GRcvIg0/bin/gunicorn \ - --access-logfile - \ - --workers 3 \ - --bind unix:/run/gunicorn.sock \ + --config ./gunicorn.conf.py \ itacpc.wsgi:application [Install]