[nextcloud] problems with nextcloud-setup.service

Hello Nix!

It is not the first time I setup a container with a Nextcloud instance but it’s the first time I try to use a database server external to the container.

The nextcloud service in my container is defined this way:

    services.nextcloud = {
      enable = true;
      nginx.enable = true;
      hostName = "cloud.narratron.io";
      https = true;
      maxUploadSize = "512M";
      config = {
        dbtype = "pgsql";
        dbhost = "pgsql001.local";
        dbuser = "narratron_cloud";
        dbname = "narratron_cloud";
    	dbpassFile = "/etc/nixos/secrets/narratron_cloud_dbpass";
        adminuser = "admin";
        adminpassFile = "/etc/nixos/secrets/narratron_cloud_adminpass";
      };
    };

The database user and the actual database are created and ready to connect on pgsql001.local.

When I start the service in the container I get this error from nextcloud-setup.service:

Dec 05 16:51:04 narratron systemd[1]: Starting nextcloud-setup.service...
Dec 05 16:51:04 narratron sudo[286]:     root : TTY=unknown ; PWD=/nix/store/1lapypfbyizjbm7fn0i73h1r350r0y4z-nextcloud-16.0.6 ; USER=nextcloud ; ENV=NEXTCLOUD_CONFIG_DIR=/var/lib/nextcloud/config ; COMMAND=/nix/store/g9d7l4fk1bn8bw36xacii7lqjb1ygrpx-php-7.3.11/bin/php -c /nix/store/q1rzk8fs1zj4ci1h5qrjnhyqclr0spj9-php.ini occ maintenance:install --admin-pass XXXXXXXX --admin-user admin --data-dir /var/lib/nextcloud/data --database pgsql --database-host pgsql001.local --database-name narratron_cloud --database-pass XXXXXXXX --database-user narratron_cloud
Dec 05 16:51:04 narratron sudo[286]: pam_unix(sudo:session): session opened for user nextcloud by (uid=0)
Dec 05 16:51:15 narratron Nextcloud[294]: {no app in context} Error occurred while checking PostgreSQL version, assuming >= 9
[...]
Dec 05 16:51:21 narratron Nextcloud[294]: {no app in context} Error trying to connect as "postgres", assuming database is setup and tables need to be created
Dec 05 16:51:27 narratron dsz53qrbv5ncx0lw7jbpvz6mljj60afm-unit-script-nextcloud-setup-start[274]: Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: No route to host
Dec 05 16:51:27 narratron dsz53qrbv5ncx0lw7jbpvz6mljj60afm-unit-script-nextcloud-setup-start[274]:         Is the server running on host "pgsql001.local" (192.168.133.225) and accepting
Dec 05 16:51:27 narratron dsz53qrbv5ncx0lw7jbpvz6mljj60afm-unit-script-nextcloud-setup-start[274]:         TCP/IP connections on port 5432?
Dec 05 16:51:27 narratron dsz53qrbv5ncx0lw7jbpvz6mljj60afm-unit-script-nextcloud-setup-start[274]:  ->
Dec 05 16:51:27 narratron systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Dec 05 16:51:27 narratron systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Dec 05 16:51:27 narratron systemd[1]: Failed to start nextcloud-setup.service.

I can connect from the container to the DB server via pgsql using the configured dbuser to the configured dbpassword, so It seems there are no problems on the server side and the database is there, owned by the database user I configured.

Please does someone reading have any hint on this?
Have you please one example of nextcloud.service using an external database server?

Thanks in advance. Gio’.

Reply to self: do not use underscores in database user names, never, ever again!

I solved this changing from dbuser = "narratron_cloud"; to dbuser = "nrrcloud";

Oh my! :triumph:

4 Likes