Seahub cannot run as non-root user

Hello,

I am having issues running Seahub as a non-root user using an SQLite 3 database (seahub.sh start)

The non-root user has ownership of all directories related to Seahub.

2022-05-01 20:44:51,079 [ERROR] django.request:224 log_response Internal Server Error: /accounts/login/
Traceback (most recent call last):
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/sqlite3/base.py", line 423, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: attempt to write a readonly database

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

Traceback (most recent call last):
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/utils/deprecation.py", line 119, in __call__
    response = self.process_response(request, response)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/contrib/sessions/middleware.py", line 61, in process_response
    request.session.save()
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/contrib/sessions/backends/db.py", line 81, in save
    return self.create()
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/contrib/sessions/backends/db.py", line 55, in create
    self.save(must_create=True)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/contrib/sessions/backends/db.py", line 87, in save
    obj.save(force_insert=must_create, force_update=not must_create, using=using)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/models/base.py", line 776, in save_base
    updated = self._save_table(
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/models/base.py", line 881, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/models/base.py", line 919, in _do_insert
    return manager._insert(
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/models/query.py", line 1270, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/models/sql/compiler.py", line 1416, in execute_sql
    cursor.execute(sql, params)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/utils.py", line 79, in _execute
    with self.db.wrap_database_errors:
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/sqlite3/base.py", line 423, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: attempt to write a readonly database
2022-05-01 20:44:52,445 [ERROR] django.request:224 log_response Internal Server Error: /accounts/login/
Traceback (most recent call last):
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/seafile/seafile-server-9.0.2/seahub/thirdpart/django/db/backends/sqlite3/base.py", line 423, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: attempt to write a readonly database

Quite at the end of your log it is said that you are trying to write to a readonly database. As this post on StackOverflow points out “Attempt to write to readonly database”, the user that wants to write to the database also needs write permissions on the directory, the database resides in. Maybe that’s the problem in your case.

It appears that my user has write permissions on the entire Seafile directory.

Maybe a dumb question, but if you say entire, you mean the seafile directory and every file and subdirectory in it? Perhaps you could post the permissions of the containing directory and the database.

Definitely not a dumb question! The entire subdirectory is owned by my user (I am executing the script under my own account for now). The data directory is on an external mount, if that helps.

Mmh, maybe you could backup the database and then open the original database with the cli of sqlite under the user that runs seafile. In this case if you have the same problem, one can conclude that there is no misconfiguration in Seafile.
Otherwise, maybe trivial, you could take a look into the list of running processes and check if seafile is really running under the user you expect. I don’t know if you start Seafile over your init system or manually and so perhaps something goes wrong there.

1 Like

Looks like I did not have execute permissions on the database files, only read and write.

Thank you for your help!