sissbruecker / linkding

Self-hosted bookmark manager that is designed be to be minimal, fast, and easy to set up using Docker.
https://linkding.link/
MIT License
6.69k stars 316 forks source link

Server 500 error - could not connect to server: Connection refused #423

Closed nodecentral closed 1 year ago

nodecentral commented 1 year ago

Hi,

I’m trying to use the following single docker.compose, however upon creation and opening up the url, i get a Server 500 error.

version: '3'

services:
  linkding:
    container_name: linkding
    image: sissbruecker/linkding:latest
    ports:
      - "9091:9090"
    volumes:
      - /share/Container/linkding:/etc/linkding/data
    environment:
      LD_DB_ENGINE: postgres
      LD_DB_DATABASE: linkding
      LD_DB_USER: linkding
      LD_DB_PASSWORD: linkding
    restart: unless-stopped

Extract from the logs below, which suggests a connectivity issue, but not sure how to address, I expected the other environment defaults would cover everything else ?…

Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 187, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    if test_func(request.user):
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 51, in <lambda>
    lambda u: u.is_authenticated,
  File "/opt/venv/lib/python3.10/site-packages/django/utils/functional.py", line 266, in inner
    self._setup()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/functional.py", line 419, in _setup
    self._wrapped = self._setupfunc()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 25, in <lambda>
    request.user = SimpleLazyObject(lambda: get_user(request))
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 11, in get_user
    request._cached_user = auth.get_user(request)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/__init__.py", line 191, in get_user
    user_id = _get_user_session_key(request)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/__init__.py", line 60, in _get_user_session_key
    return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 53, in __getitem__
    return self._session[key]
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 192, in _get_session
    self._session_cache = self.load()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 42, in load
    s = self._get_session_from_db()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 32, in _get_session_from_db
    return self.model.objects.get(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 646, in get
    num = len(clone)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 376, in __len__
    self._fetch_all()
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1866, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 87, in __iter__
    results = compiler.execute_sql(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1396, in execute_sql
    cursor = self.connection.cursor()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
    return self._cursor()
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
    self.ensure_connection()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
    with self.wrap_database_errors:
  File "/opt/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?

[pid: 19|app: 0|req: 14/22] 192.168.102.32 () {38 vars in 1627 bytes} [Tue Feb  7 09:43:31 2023] GET /bookmarks => generated 145 bytes in 51 msecs (HTTP/1.1 500) 8 headers in 282 bytes (1 switches on core 1)
2023-02-07 09:43:35,519 ERROR Internal Server Error: /health
[pid: 19|app: 0|req: 15/23] 127.0.0.1 () {28 vars in 306 bytes} [Tue Feb  7 09:43:35 2023] GET /health => generated 44 bytes in 23 msecs (HTTP/1.1 500) 8 headers in 262 bytes (1 switches on core 0)
2023-02-07 09:44:05,793 ERROR Internal Server Error: /health
[pid: 19|app: 0|req: 16/24] 127.0.0.1 () {28 vars in 306 bytes} [Tue Feb  7 09:44:05 2023] GET /health => generated 44 bytes in 20 msecs (HTTP/1.1 500) 8 headers in 262 bytes (1 switches on core 1)
2023-02-07 09:44:35,980 ERROR Internal Server Error: /health
nodecentral commented 1 year ago

Just to add, I’ve tried a compose with most of the environment variables too (see below) , but still get the same error

version: '3'

services:
  linkding:
    container_name: linkding
    image: sissbruecker/linkding:latest
    ports:
      - "9091:9090"
    volumes:
      - /share/Container/linkding:/etc/linkding/data
    environment:
      # Docker container name
      LD_CONTAINER_NAME: linkding
      # Port on the host system that the application should be published on
      LD_HOST_PORT: 9091
      # Directory on the host system that should be mounted as data dir into the Docker container
      LD_HOST_DATA_DIR: /share/Container/linkding/
      # Must end with a slash `/`
      LD_CONTEXT_PATH:
      # Username of the initial superuser to create, leave empty to not create one
      LD_SUPERUSER_NAME:
      # Password for the initial superuser, leave empty to disable
      LD_SUPERUSER_PASSWORD:
      # Option to disable background tasks
      LD_DISABLE_BACKGROUND_TASKS: False
      # Option to disable URL validation for bookmarks completely
      LD_DISABLE_URL_VALIDATION: False
      # Enables support for authentication proxies such as Authelia
      LD_ENABLE_AUTH_PROXY: False
      LD_DB_ENGINE: postgres
      LD_DB_DATABASE: linkding
      LD_DB_USER: linkding
      LD_DB_PASSWORD: linkding
    restart: unless-stopped
MarioNoll commented 1 year ago

The connection to your postgres database is not working. You need to either remove the enviroment variables so linkding will use sqlite as default:

By default, linkding uses SQLite as a database. Alternatively linkding supports PostgreSQL, see the database options for more information.

Or alternatively setup a postgres instance on your own e.g.

postgres:
  image: postgres:13.9
  restart: unless-stopped
  volumes:
    - postgres:/var/lib/postgresql/data
  environment:
    POSTGRES_DB: "linkding"
    POSTGRES_USER: "linkding"
    POSTGRES_PASSWORD: "linkding"
nodecentral commented 1 year ago

Hi,

Thanks for responding,

I went with postgresdb as I already have an instance set up for another container, (paperless-ngx)

db:
    image: postgres:14
    container_name: paperless-db
    restart: always
    volumes:
      - /share/Container/paperlessdb:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: paperless
      POSTGRES_USER: paperless
      POSTGRES_PASSWORD: paperless

Can I use that or should I creare a new one dedicated to linkding ?

nodecentral commented 1 year ago

If on it’s own, would it be something like this, with a depends_on added ?


version: '3'

services:
  db:
    image: postgres:14
    container_name: linkding-db
    restart: unless-stopped
    volumes:
      - /share/Container/linkding:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: linkding
      POSTGRES_USER: linkding
      POSTGRES_PASSWORD: linkding

  linkding:
    container_name: linkding
    image: sissbruecker/linkding:latest
    ports:
      - "9091:9090"
    volumes:
      - /share/Container/linkding/db:/etc/linkding/data
   depends_on:
      - db
    restart: unless-stopped
MarioNoll commented 1 year ago

In your initial error message linkding is trying to connect to postgres on localhost, you need to set LD_DB_HOST to the container name of your postgres instance, similar to how you probably set it up for paperless via PAPERLESS_DBHOST.

nodecentral commented 1 year ago

Thank @MarioNoll,

I went with the following in the end, which has got me to the login screen..


version: '3'

services:
  linkding:
    container_name: linkding
    image: sissbruecker/linkding:latest
    depends_on:
      - db
    ports:
      - "9091:9090"
    volumes:
      - /share/Container/linkding:/etc/linkding/data
    environment:
      LD_DB_ENGINE: postgres
      LD_DB_DATABASE: linkding
      LD_DB_USER: linkding
      LD_DB_PASSWORD: linkding
      LD_DB_HOST: db
    restart: unless-stopped

  db:
    image: postgres:14
    container_name: linkding-db
    volumes:
      - /share/Container/linkdingdb:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: paperless
      POSTGRES_USER: paperless
      POSTGRES_PASSWORD: paperless
    restart: always

both the Linkding and postgres containers seems to be running, however my next issue is that I get the following errors when I try and create the initial user..

/] # docker exec -it linkding python manage.py createsuperuser --username=myname --email=my.email.uk@gmail.com
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  password authentication failed for user "linkding"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/etc/linkding/manage.py", line 21, in <module>
    main()
  File "/etc/linkding/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 88, in execute
    return super().execute(*args, **options)
  File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 447, in execute
    self.check_migrations()
  File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 564, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__
    self.build_graph()
  File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
    if self.has_table():
  File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table
    with self.connection.cursor() as cursor:
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
    return self._cursor()
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
    self.ensure_connection()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
    with self.wrap_database_errors:
  File "/opt/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL:  password authentication failed for user "linkding"

I tried the docker-compose option too, which didn’t do anything, it didn’t prompt me for a password ..

MarioNoll commented 1 year ago

You are setting up linkding with these values

LD_DB_DATABASE: linkding
LD_DB_USER: linkding
LD_DB_PASSWORD: linkding

But you did setup postgres with these values

POSTGRES_DB: paperless
POSTGRES_USER: paperless
POSTGRES_PASSWORD: paperless

Name of the database, user and password must be coherent, that's probably why you get a password authentication error.

nodecentral commented 1 year ago

Thanks again @MarioNoll , my mistake, I was too hasty…

The docker compose is as follows, but I’m back to the Server 500 error message again.

version: '3'

services:
  db:
    container_name: linkding-db
    image: postgres:14
    volumes:
      - /share/Container/linkding/db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: linkding
      POSTGRES_USER: linkding
      POSTGRES_PASSWORD: linkding
    restart: always

  linkding:
    container_name: linkding
    image: sissbruecker/linkding:latest
    depends_on:
      - db
    ports:
      - "9091:9090"
    volumes:
      - /share/Container/linkding:/etc/linkding/data
    environment:
      LD_DB_ENGINE: postgres
      LD_DB_DATABASE: linkding
      LD_DB_USER: linkding
      LD_DB_PASSWORD: linkding
      LD_DB_HOST: db
    restart: unless-stopped

Here’s the log extract..

2023-02-08 08:28:21,024 INFO Skip creating initial superuser, LD_SUPERUSER_NAME option is not defined
chown: cannot access '/etc/linkding/data/db/base/16384': No such file or directory
[uWSGI] getting INI configuration from uwsgi.ini
[uwsgi-static] added mapping for /static => static
[uwsgi-static] added mapping for /static => data/favicons
*** Starting uWSGI 2.0.20 (64bit) on [Wed Feb  8 08:28:23 2023] ***
compiled with version: 8.3.0 on 20 January 2023 20:30:39
os: Linux-5.10.60-qnap #1 SMP Thu Dec 15 05:12:00 CST 2022
nodename: 4d5f946bc08c
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /etc/linkding
writing pidfile to /tmp/linkding.pid
detected binary path: /opt/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
setgid() to 33
setuid() to 33
your processes number limit is 63255
your memory page size is 4096 bytes
detected max file descriptor number: 65535
building mime-types dictionary from file /etc/mime.types...565 entry found
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :9090 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:43159 (port auto-assigned) fd 3
Python version: 3.10.6 (main, Aug 23 2022, 08:58:52) [GCC 8.3.0]
Python main interpreter initialized at 0x556bc3863610
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 274608 bytes (268 KB) for 4 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 5 seconds on interpreter 0x556bc3863610 pid: 1 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1)
spawned uWSGI worker 1 (pid: 25, cores: 2)
spawned uWSGI worker 2 (pid: 27, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 14 ***
spawned uWSGI http 1 (pid: 29)
[pid: 27|app: 0|req: 1/1] 172.29.252.1 () {32 vars in 374 bytes} [Wed Feb  8 08:28:32 2023] GET / => generated 0 bytes in 892 msecs (HTTP/1.1 302) 9 headers in 275 bytes (1 switches on core 0)
2023-02-08 08:28:39,060 ERROR Internal Server Error: /bookmarks
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 187, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  database "linkding" does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    if test_func(request.user):
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 51, in <lambda>
    lambda u: u.is_authenticated,
  File "/opt/venv/lib/python3.10/site-packages/django/utils/functional.py", line 266, in inner
    self._setup()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/functional.py", line 419, in _setup
    self._wrapped = self._setupfunc()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 25, in <lambda>
    request.user = SimpleLazyObject(lambda: get_user(request))
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 11, in get_user
    request._cached_user = auth.get_user(request)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/__init__.py", line 191, in get_user
    user_id = _get_user_session_key(request)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/__init__.py", line 60, in _get_user_session_key
    return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 53, in __getitem__
    return self._session[key]
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 192, in _get_session
    self._session_cache = self.load()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 42, in load
    s = self._get_session_from_db()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 32, in _get_session_from_db
    return self.model.objects.get(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 646, in get
    num = len(clone)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 376, in __len__
    self._fetch_all()
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1866, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 87, in __iter__
    results = compiler.execute_sql(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1396, in execute_sql
    cursor = self.connection.cursor()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
    return self._cursor()
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
    self.ensure_connection()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
    with self.wrap_database_errors:
  File "/opt/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL:  database "linkding" does not exist

[pid: 27|app: 0|req: 2/2] 192.168.102.32 () {38 vars in 1667 bytes} [Wed Feb  8 08:28:38 2023] GET /bookmarks => generated 145 bytes in 602 msecs (HTTP/1.1 500) 8 headers in 282 bytes (1 switches on core 1)
[pid: 27|app: 0|req: 3/3] 172.29.252.1 () {32 vars in 374 bytes} [Wed Feb  8 08:28:40 2023] GET / => generated 0 bytes in 1 msecs (HTTP/1.1 302) 9 headers in 275 bytes (1 switches on core 0)
2023-02-08 08:28:50,050 ERROR Internal Server Error: /health
[pid: 27|app: 0|req: 4/4] 127.0.0.1 () {28 vars in 306 bytes} [Wed Feb  8 08:28:50 2023] GET /health => generated 44 bytes in 30 msecs (HTTP/1.1 500) 8 headers in 262 bytes (1 switches on core 1)
[pid: 27|app: 0|req: 5/5] 172.29.252.1 () {32 vars in 372 bytes} [Wed Feb  8 08:29:14 2023] GET / => generated 0 bytes in 1 msecs (HTTP/1.1 302) 9 headers in 275 bytes (1 switches on core 0)
MarioNoll commented 1 year ago

django.db.utils.OperationalError: FATAL: database "linkding" does not exist

I'm guessing changing the postgres environment variables did not have any effect, due to the data being persisted here:

    volumes:
      - /share/Container/linkding/db:/var/lib/postgresql/data

Should work if you delete the files in /share/Container/linkding/db and bring up the containers again.

nodecentral commented 1 year ago

Hi @MarioNoll , sorry I cleared out the content of the mapped volumes and tried again but I still get the 500 error. Although this time a new error - see log extract below..

*** Stats server enabled on 127.0.0.1:9191 fd: 14 ***
spawned uWSGI http 1 (pid: 19)
2023-02-08 22:50:38,167 ERROR Internal Server Error: /health
[pid: 18|app: 0|req: 1/1] 127.0.0.1 () {28 vars in 306 bytes} [Wed Feb  8 22:50:38 2023] GET /health => generated 44 bytes in 156 msecs (HTTP/1.1 500) 8 headers in 262 bytes (1 switches on core 0)
2023-02-08 22:51:08,463 ERROR Internal Server Error: /health
[pid: 18|app: 0|req: 2/2] 127.0.0.1 () {28 vars in 306 bytes} [Wed Feb  8 22:51:08 2023] GET /health => generated 44 bytes in 25 msecs (HTTP/1.1 500) 8 headers in 262 bytes (1 switches on core 1)
[pid: 18|app: 0|req: 3/3] 172.29.4.1 () {32 vars in 372 bytes} [Wed Feb  8 22:51:19 2023] GET / => generated 0 bytes in 23 msecs (HTTP/1.1 302) 9 headers in 275 bytes (1 switches on core 0)
[pid: 17|app: 0|req: 1/4] 192.168.102.32 () {40 vars in 1693 bytes} [Wed Feb  8 22:51:22 2023] GET / => generated 0 bytes in 133 msecs (HTTP/1.1 302) 9 headers in 278 bytes (1 switches on core 0)
2023-02-08 22:51:22,379 ERROR Internal Server Error: /bookmarks
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 187, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  could not open file "global/pg_filenode.map": Permission denied

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/opt/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    if test_func(request.user):
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 51, in <lambda>
    lambda u: u.is_authenticated,
  File "/opt/venv/lib/python3.10/site-packages/django/utils/functional.py", line 266, in inner
    self._setup()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/functional.py", line 419, in _setup
    self._wrapped = self._setupfunc()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 25, in <lambda>
    request.user = SimpleLazyObject(lambda: get_user(request))
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/middleware.py", line 11, in get_user
    request._cached_user = auth.get_user(request)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/__init__.py", line 191, in get_user
    user_id = _get_user_session_key(request)
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/auth/__init__.py", line 60, in _get_user_session_key
    return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 53, in __getitem__
    return self._session[key]
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/base.py", line 192, in _get_session
    self._session_cache = self.load()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 42, in load
    s = self._get_session_from_db()
  File "/opt/venv/lib/python3.10/site-packages/django/contrib/sessions/backends/db.py", line 32, in _get_session_from_db
    return self.model.objects.get(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 646, in get
    num = len(clone)
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 376, in __len__
    self._fetch_all()
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1866, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/query.py", line 87, in __iter__
    results = compiler.execute_sql(
  File "/opt/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1396, in execute_sql
    cursor = self.connection.cursor()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
    return self._cursor()
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
    self.ensure_connection()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
    with self.wrap_database_errors:
  File "/opt/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL:  could not open file "global/pg_filenode.map": Permission denied

[pid: 17|app: 0|req: 2/5] 192.168.102.32 () {38 vars in 1667 bytes} [Wed Feb  8 22:51:22 2023] GET /bookmarks => generated 145 bytes in 124 msecs (HTTP/1.1 500) 8 headers in 282 bytes (1 switches on core 1)
2023-02-08 22:51:38,784 ERROR Internal Server Error: /health
[pid: 18|app: 0|req: 4/6] 127.0.0.1 () {28 vars in 304 bytes} [Wed Feb  8 22:51:38 2023] GET /health => generated 44 bytes in 24 msecs (HTTP/1.1 500) 8 headers in 262 bytes (1 switches on core 1)
2023-02-08 22:52:09,119 ERROR Internal Server Error: /health
[pid: 18|app: 0|req: 5/7] 127.0.0.1 () {28 vars in 306 bytes} [Wed Feb  8 22:52:09 2023] GET /health => generated 44 bytes in 41 msecs (HTTP/1.1 500) 8 headers in 262 bytes (1 switches on core 0)

I can see the file it’s talking about, and here are the permissions that it’s give by Linking..


[/share/Container/linkding/db] # ls -la
total 136
drwx------ 19 33 33  4096 2023-02-08 22:50 ./
drwx------  4 33 33  4096 2023-02-08 22:47 ../
drwx------  6 33 33  4096 2023-02-08 22:48 base/
drwx------  2 33 33  4096 2023-02-08 22:50 global/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_commit_ts/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_dynshmem/
-rw-------  1 33 33  4821 2023-02-08 22:47 pg_hba.conf
-rw-------  1 33 33  1636 2023-02-08 22:47 pg_ident.conf
drwx------  4 33 33  4096 2023-02-08 22:50 pg_logical/
drwx------  4 33 33  4096 2023-02-08 22:47 pg_multixact/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_notify/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_replslot/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_serial/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_snapshots/
drwx------  2 33 33  4096 2023-02-08 22:50 pg_stat/
drwx------  2 33 33  4096 2023-02-08 22:50 pg_stat_tmp/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_subtrans/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_tblspc/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_twophase/
-rw-------  1 33 33     3 2023-02-08 22:47 PG_VERSION
drwx------  3 33 33  4096 2023-02-08 22:47 pg_wal/
drwx------  2 33 33  4096 2023-02-08 22:47 pg_xact/
-rw-------  1 33 33    88 2023-02-08 22:47 postgresql.auto.conf
-rw-------  1 33 33 28835 2023-02-08 22:47 postgresql.conf
-rw-------  1 33 33    36 2023-02-08 22:50 postmaster.opts
-rw-------  1 33 33    94 2023-02-08 22:50 postmaster.pid

any ideas ?

MarioNoll commented 1 year ago

@nodecentral Did you restart containers after removing the persisted data?

nodecentral commented 1 year ago

Hi, I did yes, same result server 500 error.

Are you able to try my docker_compose?

version: '3'

services:
  db:
    container_name: linkding-db
    image: postgres:14
    volumes:
      - /share/Container/linkding/db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: linkding
      POSTGRES_USER: linkding
      POSTGRES_PASSWORD: linkding
    restart: always

  linkding:
    container_name: linkding
    image: sissbruecker/linkding:latest
    depends_on:
      - db
    ports:
      - "9091:9090"
    volumes:
      - /share/Container/linkding:/etc/linkding/data
    environment:
      LD_DB_ENGINE: postgres
      LD_DB_DATABASE: linkding
      LD_DB_USER: linkding
      LD_DB_PASSWORD: linkding
      LD_DB_HOST: db
    restart: unless-stopped 
MarioNoll commented 1 year ago

@nodecentral Try LD_DB_HOST: linkding-db

Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

More info here https://docs.docker.com/compose/networking/

nodecentral commented 1 year ago

That was it !! thanks so much for your patience @MarioNoll