KDE Kontact applications fail to start. The Akonadi personal information management service is not operational

Solution

The error logs show that the akonadi verion of the mysql server that these K* applications require is trying to access ~/.local/share/akonadi/db_data/ except db_data doesn't exist, so it throws an error much like touch ~/nonexistent_dir/file.txt would.

To solve, simply run the below commands. cd ~/.local/share/akonadi/; mkdir db_data


Explaination

After doing a lot of digging around on the internet (there was a decent amount of information but most of it was incomplete/unsolved forum threads about similar but not identical issues with Akonadi) I was able to find this general summary of Akonadi from KDE which was an excellent kickstart into my own investigating.

After playing around with the commands mentioned in the link, I got the following output (redactions mine):

$ akonadictl start
$ Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
mysqld: [ERROR] Could not open required defaults file: /home/[my username]/.config/akonadi/
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
org.kde.pim.akonadiserver: database server stopped unexpectedly
org.kde.pim.akonadiserver: Database process exited unexpectedly during initial connection!
org.kde.pim.akonadiserver: executable: "/usr/sbin/mysqld-akonadi"
org.kde.pim.akonadiserver: arguments: ("--defaults-file=/home/[my username]/.local/share/akonadi/mysql.conf", "--datadir=/home/[my username]/.local/share/akonadi/db_data/", "--socket=/tmp/akonadi-[my username].UXCgLp/mysql.socket", "--pid-file=/tmp/akonadi-[my username].UXCgLp/mysql.pid")
org.kde.pim.akonadiserver: stdout: ""
org.kde.pim.akonadiserver: stderr: "mysqld: Can't change dir to '/home/[my username]/.local/share/akonadi/db_data/' (Errcode: 2 - No such file or directory)\n2018-06-21T19:34:18.989616Z 0 [Warning] The syntax '--log_warnings/-W' is deprecated and will be removed in a future release. Please use '--log_error_verbosity' instead.\n2018-06-21T19:34:18.989703Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).\n2018-06-21T19:34:18.991172Z 0 [Warning] Can't create test file /home/[my username]/.local/share/akonadi/db_data/[my hostname].lower-test\n2018-06-21T19:34:18.992274Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.22-0ubuntu0.16.04.1) starting as process 11859 ...\n2018-06-21T19:34:19.006500Z 0 [Warning] Can't create test file /home/[my username]/.local/share/akonadi/db_data/[my hostname].lower-test\n2018-06-21T19:34:19.006549Z 0 [Warning] Can't create test file /home/[my username]/.local/share/akonadi/db_data/[my hostname].lower-test\n2018-06-21T19:34:19.006623Z 0 [ERROR] failed to set datadir to /home/[my username]/.local/share/akonadi/db_data/\n2018-06-21T19:34:19.006632Z 0 [ERROR] Aborting\n\n2018-06-21T19:34:19.006658Z 0 [Note] Binlog end\n2018-06-21T19:34:19.006726Z 0 [Note] /usr/sbin/mysqld: Shutdown complete\n\n"
org.kde.pim.akonadiserver: exit code: 1
org.kde.pim.akonadiserver: process error: "Unknown error"
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/akonadi-[my username].UXCgLp/mysql.socket' (2)'
Check that mysqld is running and that the socket: '/tmp/akonadi-[my username].UXCgLp/mysql.socket' exists!
org.kde.pim.akonadiserver: Failed to remove runtime connection config file
org.kde.pim.akonadicontrol: Application 'akonadiserver' exited normally...

This produces a couple interesting lines. The problematic one being org.kde.pim.akonadiserver: stderr: "mysqld: Can't change dir to '/home/[my username]/.local/share/akonadi/db_data/' (Errcode: 2 - No such file or directory). To me this looked like the program was trying to write to a directory to which it didn't have access and was throwing an error, much like touch ~/nonexistent_dir/file.txt would.

So I ran cd ~/.local/share/akonadi/; mkdir db_data and retried it. Bam it worked.


Similar problem, different solution. Mine was diagnosed as such:

$ akonadictl --verbose start                                      
....
org.kde.pim.akonadiserver: Executing: "/usr/sbin/mysqld-akonadi" "--defaults-file=/home/dargaud/.local/share/akonadi/mysql.conf --datadir=/home/dargaud/.local/share/akonadi/db_data/ --socket=/run/user/10705/akonadi/mysql.socket --pid-file=/run/user/10705/akonadi/mysql.pid"
org.kde.pim.akonadiserver: database server stopped unexpectedly

$ tail /var/log/syslog                      
audit: type=1400 audit(1593423663.888:404): apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/home/dargaud/.local/share/akonadi/db_data/mysqld_tmp_file_case_insensitive_test.lower-test" pid=156675 comm="mysqld-akonadi" requested_mask="c" denied_mask="c" fsuid=10705 ouid=10705

Solution, adding the following two lines to the apparmor config file for mysqld:

$ sudo nano /etc/apparmor.d/usr.sbin.mysqld
/{,var/}run/user/[0-9]*/akonadi/** rw,
/home/*/.local/share/akonadi/** rwk,

Followed by:

$ sudo systemctl restart apparmor.service
$ akonadictl --verbose start 

Tags:

Kde5

Kde Neon