Nextcloud prevents systemd automount umount from working

Hello

I installed Nextcloud on a raspberry pi 4 (Linux 5.4.74-1-ARCH armv7l) according to this article, with MariaDB as database and Apache as web server. I have also set up the Apache PHP module according to this article.

An external hard drive is connected to the Raspi via USB and mariadb and nextcloud need the drive for their data directories.
root@raspi-99 / # ls -al /media/hdd-linux 
insgesamt 36
drwxrwxr-x 6 titan99 titan99  4096  2. Nov 08:05 .
drwxr-xr-x 3 root    root     4096  3. Okt 08:45 ..
drwxrwxr-x 6 mysql   mysql    4096  8. Nov 21:23 mysql
drwxr-x--- 3 http    http     4096  1. Nov 09:36 nextcloud
The data directory is mounted with systemd automount.
root@raspi-99 / # cat /etc/fstab | grep hdd-linux
UUID=d39147b7-ab0c-49b8-9200-d38a51a3023e /media/hdd-linux auto noauto,nofail,x-systemd.automount,x-systemd.idle-timeout=120s,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s,_netdev,x-systemd.requires=network-online.target 0 2
Everything works fine, except for umount.
root@raspi-99 / # journalctl -r -u media-hdd\\x2dlinux.mount -u media-hdd\\x2dlinux.automount
Nov 08 23:46:03 raspi-99 systemd[1]: Failed unmounting /media/hdd-linux.
Nov 08 23:46:03 raspi-99 systemd[1]: media-hdd\x2dlinux.mount: Mount process exited, code=exited, status=32/n/a
Nov 08 23:46:03 raspi-99 umount[13124]: umount: /media/hdd-linux: das Ziel wird gerade benutzt.
Nov 08 23:46:03 raspi-99 systemd[1]: Unmounting /media/hdd-linux...
Nov 08 23:44:02 raspi-99 systemd[1]: Failed unmounting /media/hdd-linux.
Nov 08 23:44:02 raspi-99 systemd[1]: media-hdd\x2dlinux.mount: Mount process exited, code=exited, status=32/n/a
Nov 08 23:44:02 raspi-99 umount[13109]: umount: /media/hdd-linux: das Ziel wird gerade benutzt.
Nov 08 23:44:02 raspi-99 systemd[1]: Unmounting /media/hdd-linux...
Nov 08 23:42:02 raspi-99 systemd[1]: Failed unmounting /media/hdd-linux.
Nov 08 23:42:02 raspi-99 systemd[1]: media-hdd\x2dlinux.mount: Mount process exited, code=exited, status=32/n/a
Nov 08 23:42:02 raspi-99 umount[13090]: umount: /media/hdd-linux: das Ziel wird gerade benutzt.
Nov 08 23:42:02 raspi-99 systemd[1]: Unmounting /media/hdd-linux...
Nov 08 21:22:53 raspi-99 systemd[1]: Mounted /media/hdd-linux.
Nov 08 21:22:52 raspi-99 systemd[1]: Mounting /media/hdd-linux...
Nov 08 21:22:44 raspi-99 systemd[1]: media-hdd\x2dlinux.automount: Got automount request for /media/hdd-linux, triggered by 530 (mariadbd)
-- Reboot --
Nov 08 21:22:42 raspi-99 systemd[1]: media-hdd\x2dlinux.mount: Failed with result 'exit-code'.
Nov 08 21:22:42 raspi-99 systemd[1]: Unset automount media-hdd\x2dlinux.automount.
Nov 08 21:22:42 raspi-99 systemd[1]: media-hdd\x2dlinux.automount: Succeeded.
Nov 08 21:22:39 raspi-99 systemd[1]: Failed unmounting /media/hdd-linux.
Nov 08 21:22:39 raspi-99 systemd[1]: media-hdd\x2dlinux.mount: Mount process exited, code=exited, status=32/n/a
Nov 08 21:22:39 raspi-99 umount[12009]: umount: /media/hdd-linux: das Ziel wird gerade benutzt.
Nov 08 21:22:39 raspi-99 systemd[1]: Unmounting /media/hdd-linux...
Nov 08 21:04:00 raspi-99 systemd[1]: Mounted /media/hdd-linux.
Nov 08 21:03:59 raspi-99 systemd[1]: Mounting /media/hdd-linux...
Nov 08 21:03:51 raspi-99 systemd[1]: media-hdd\x2dlinux.automount: Got automount request for /media/hdd-linux, triggered by 507 (mariadbd)
-- Reboot --
lines 820-876

MariaDB triggers an automount request, and about 20 minutes later, umount does not work (from then on it repeats about every 2 minutes).

I also made changes to my /etc/my.cnf.d/server.cnf file.

# this is only for the mysqld standalone daemon
[mysqld]
datadir=/media/hdd-linux/mysql
skip-networking
interactive-timeout=360
wait-timeout=360

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
idle_transaction_timeout=360

MariaDB configuration, mysqld --verbose --help | grep timeout output:

root@raspi-99 / # mysqld --verbose --help | grep timeout
connect-timeout                                              10
deadlock-timeout-long                                        50000000
deadlock-timeout-short                                       10000
delayed-insert-timeout                                       300
idle-readonly-transaction-timeout                            0
idle-transaction-timeout                                     360
idle-write-transaction-timeout                               0
innodb-flush-log-at-timeout                                  1
innodb-lock-wait-timeout                                     50
innodb-rollback-on-timeout                                   FALSE
interactive-timeout                                          360
lock-wait-timeout                                            86400
net-read-timeout                                             30
net-write-timeout                                            60
port-open-timeout                                            0
rpl-semi-sync-master-timeout                                 10000
rpl-semi-sync-slave-kill-conn-timeout                        5
slave-net-timeout                                            60
thread-pool-idle-timeout                                     60
wait-timeout                                                 360

But this did not lead to the desired result.

Does anyone know?

EDIT: In the meantime I found the console command fuser -mv /media/hdd-linux which gives more detailed information about who is using currently the filesystem. I hope this takes me a step further.

When Nextcloud is loading data? (Nextcloud opened via the browser).

Dieser Text wird ausgeblendet

root@raspi-99 /media/hdd-linux # fuser -mv /media/hdd-linux
                     BEN.        PID ZUGR.  BEFEHL
/media/hdd-linux:    root     kernel mount /media/hdd-linux
                     mysql       538 F.c.. mariadbd
                     http       1483 f.... php-fcgid-wrapp
                     root      12580 ..c.. zsh
                     root      12632 f.c.. smbd
                     http      12765 f.... php-fcgid-wrapp
                     http      12807 f.... php-fcgid-wrapp
                     http      12830 f.... php-fcgid-wrapp
                     http      12842 f.... php-fcgid-wrapp
After a few moments.

Dieser Text wird ausgeblendet

root@raspi-99 /media/hdd-linux # fuser -mv /media/hdd-linux
                     BEN.        PID ZUGR.  BEFEHL
/media/hdd-linux:    root     kernel mount /media/hdd-linux
                     mysql       538 F.c.. mariadbd
                     root      12580 ..c.. zsh
                     root      12632 f.c.. smbd

So when I go out of the directory with ssh, zsh disappears from the list. If I don’t go to the samba network directory or shut down the laptop, smbd disappears from the list too. Then only mariadbd remains.
The title is perhaps too imprecise because nextcloud or php do not always use the directory directly, but mariadb.

it’s probably much more stable and much safer to use a fixed mount and service-config; eg mount all necessary filesystems and after that start the services that depend on them (db, webserver, …) use /etc/fstab and reliable service-deps. if you are not certain about your external hd you can add an error condition in case it’s not available.
the database must be running at all times for nextcloud and be started before the webserver.

this seems to me like sth. that needs fixing asap (don’t know what you’re trying to do, though). i recommend this order: shut down webserver, shut down db, …, umount filesystems, …
GOOD LUCK!

Thanks for the answer.

The services are running:

root@raspi-99 / # systemctl list-units mariadb.service httpd.service redis.service
  UNIT            LOAD   ACTIVE SUB     DESCRIPTION
  httpd.service   loaded active running Apache Web Server
  mariadb.service loaded active running MariaDB 10.5.7 database server
  redis.service   loaded active running Advanced key-value store

I’m trying that if the services don’t need the data directory, they shouldn’t block automount timeout (x-systemd.idle-timeout=120s). For example, to save electricity.