System cron not working - php_network_getaddresses: Name or service not known

Hi guys,
i’m having problem with the background cron jobs. After searching and trying for a couple of days, i still haven’t find a solution for my particular problem. So, you are my last resort :wink:

Background info:
I recently switched for the background jobs from Ajax to cron (hadn’t seen, that this is the recommended option). I switched this option in the nextcloud Web frontend as well as in the # crontab settings. Since then, i get the error view in the frontend that something is not working.
To get a better idea, i tried manually triggering cron with the following:

php -f /media/nextcloud/html/cron.php --define apc.enable_cli=1

After a couple of seconds, i get the following:

pi@raspi:/media/nextcloud/html $ sudo php -f /media/nextcloud/html/cron.php --define apc.enable_cli=1
{“reqId”:“iGzJSzgY1veDYl1o9E6a”,“level”:3,“time”:“2025-01-07T09:52:24+00:00”,“remoteAddr”:“”,“user”:“–”,“app”:“cron”,“method”:“”,“url”:“–”,“message”:“Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for nextcloud_db failed: Name or service not known”,“userAgent”:“–”,“version”:“30.0.4.1”,“exception”:{“Exception”:“Doctrine\DBAL\Exception”,“Message”:“Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for nextcloud_db failed: Name or service not known”,“Code”:2002,“Trace”:[{“file”:“/media/nextcloud/html/3rdparty/doctrine/dbal/src/Connection.php”,“line”:453,“function”:“connect”,“class”:“OC\DB\Connection”,“type”:“->”},{“file”:“/media/nextcloud/html/3rdparty/doctrine/dbal/src/Connection.php”,“line”:411,“function”:“getDatabasePlatformVersion”,“class”:“Doctrine\DBAL\Connection”,“type”:“->”},{“file”:“/media/nextcloud/html/3rdparty/doctrine/dbal/src/Connection.php”,“line”:318,“function”:“detectDatabasePlatform”,“class”:“Doctrine\DBAL\Connection”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/DB/Connection.php”,“line”:899,“function”:“getDatabasePlatform”,“class”:“Doctrine\DBAL\Connection”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/DB/ConnectionAdapter.php”,“line”:235,“function”:“getDatabaseProvider”,“class”:“OC\DB\Connection”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/DB/QueryBuilder/QueryBuilder.php”,“line”:96,“function”:“getDatabaseProvider”,“class”:“OC\DB\ConnectionAdapter”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/AppConfig.php”,“line”:1211,“function”:“expr”,“class”:“OC\DB\QueryBuilder\QueryBuilder”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/AppConfig.php”,“line”:237,“function”:“loadConfig”,“class”:“OC\AppConfig”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/AppConfig.php”,“line”:1351,“function”:“searchValues”,“class”:“OC\AppConfig”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/App/AppManager.php”,“line”:126,“function”:“getValues”,“class”:“OC\AppConfig”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/App/AppManager.php”,“line”:147,“function”:“getInstalledAppsValues”,“class”:“OC\App\AppManager”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/legacy/OC_App.php”,“line”:191,“function”:“getInstalledApps”,“class”:“OC\App\AppManager”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/private/AppFramework/Bootstrap/Coordinator.php”,“line”:48,“function”:“getEnabledApps”,“class”:“OC_App”,“type”:“::”},{“file”:“/media/nextcloud/html/lib/base.php”,“line”:659,“function”:“runInitialRegistration”,“class”:“OC\AppFramework\Bootstrap\Coordinator”,“type”:“->”},{“file”:“/media/nextcloud/html/lib/base.php”,“line”:1134,“function”:“init”,“class”:“OC”,“type”:“::”},{“file”:“/media/nextcloud/html/cron.php”,“line”:24,“args”:[“/media/nextcloud/html/lib/base.php”],“function”:“require_once”}],“File”:“/media/nextcloud/html/lib/private/DB/Connection.php”,“Line”:233,“message”:“Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for nextcloud_db failed: Name or service not known”,“exception”:{},“CustomMessage”:“Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for nextcloud_db failed: Name or service not known”}}
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for nextcloud_db failed: Name or service not known in /media/nextcloud/html/lib/private/DB/Connection.php:233
Stack trace:
#0 /media/nextcloud/html/3rdparty/doctrine/dbal/src/Connection.php(453): OC\DB\Connection->connect()
#1 /media/nextcloud/html/3rdparty/doctrine/dbal/src/Connection.php(411): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /media/nextcloud/html/3rdparty/doctrine/dbal/src/Connection.php(318): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /media/nextcloud/html/lib/private/DB/Connection.php(899): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /media/nextcloud/html/lib/private/DB/ConnectionAdapter.php(235): OC\DB\Connection->getDatabaseProvider()
#5 /media/nextcloud/html/lib/private/DB/QueryBuilder/QueryBuilder.php(96): OC\DB\ConnectionAdapter->getDatabaseProvider()
#6 /media/nextcloud/html/lib/private/AppConfig.php(1211): OC\DB\QueryBuilder\QueryBuilder->expr()
#7 /media/nextcloud/html/lib/private/AppConfig.php(237): OC\AppConfig->loadConfig()
#8 /media/nextcloud/html/lib/private/AppConfig.php(1351): OC\AppConfig->searchValues()
#9 /media/nextcloud/html/lib/private/App/AppManager.php(126): OC\AppConfig->getValues()
#10 /media/nextcloud/html/lib/private/App/AppManager.php(147): OC\App\AppManager->getInstalledAppsValues()
#11 /media/nextcloud/html/lib/private/legacy/OC_App.php(191): OC\App\AppManager->getInstalledApps()
#12 /media/nextcloud/html/lib/private/AppFramework/Bootstrap/Coordinator.php(48): OC_App::getEnabledApps()
#13 /media/nextcloud/html/lib/base.php(659): OC\AppFramework\Bootstrap\Coordinator->runInitialRegistration()
#14 /media/nextcloud/html/lib/base.php(1134): OC::init()
#15 /media/nextcloud/html/cron.php(24): require_once(‘…’)
#16 {main}

This looks like a problem with the database, but my nextcloud is running for month without problems.

My nextcloud is on version 30.0.04.
It runs in a docker container on a raspberry pi 5.
As a proxy, i use traefik.
For further context, this is my docker compose file:

version: “3.8”
services:
nextcloud:
image: nextcloud:latest
container_name: nextcloud
ports:
- 4646:80
labels:
- traefik.docker.network= traefik_web
- traefik.enable=true
- traefik.http.routers.nextcloud.entrypoints=https
- traefik.http.routers.nextcloud.rule=Host(<my.domain>)
- traefik.http.middlewares.nextcloud.headers.stsSeconds=15552000
- traefik.http.middlewares.nextcloud.headers.stsPreload=true
- traefik.http.middlewares.nextcloud_redirect.redirectregex.permanent=true
- traefik.http.middlewares.nextcloud_redirect.redirectregex.regex=^https://(.*)/.well-known/(card|cal)dav
- traefik.http.middlewares.nextcloud_redirect.redirectregex.replacement=https://$${1}/remote.php/dav/
volumes:
- /media/nextcloud/html:/var/www/html
restart: unless-stopped
environment:
- MYSQL_HOST=
- MYSQL_PASSWORD=
- MYSQL_DATABASE=
- MYSQL_USER=
- TRUSTED_PROXIES=
depends_on:
- nextcloud_db
links:
- nextcloud_db
networks:
- traefik_web
#- nextcloud
logging:
options:
max-size: 5m
max-file: “3”
nextcloud_db:
image: yobasystems/alpine-mariadb
container_name: nextcloud_db
volumes:
- /media/nextcloud/db:/var/lib/mysql
restart: unless-stopped
environment:
- MYSQL_HOST=
- MYSQL_PASSWORD=
- MYSQL_DATABASE=
- MYSQL_USER=
- TRUSTED_PROXIES=
- MYSQL_ROOT_PASSWORD=
networks:
- traefik_web
logging:
options:
max-size: 5m
max-file: “3”
networks:
traefik_web:
external: true

I checked the obvious one: The environment variables are the same in the config.php. But as i mentioned, the database in general works.

Do you have any idea? What am i missing?

Thanks in advance!

hi @HeinrichXVIII welcome to the forum :handshake:

looks you are running the cron job from your host and for this reason it can’t connect to the database. for testing purposes you should run it inside of your application container using docker command like

  • docker exec nextcloud php cron.php or
  • docker exec -u 33 nextcloud php cron.php

in long term you should setup a cron “sidecar” container

many topics exist in this forum related to the problem use search and check cron tag. see more advanced examples including cron:

Thanks for the tip (i will check cron container later), i still cannot get it to work.
i run this command for testing purposes:

sudo docker exec --user www-data -it nextcloud php -f /media/nextcloud/html/cron.php --define apc.enable_cli=1

I get

Could not open input file: /media/nextcloud/html/cron.php

Looks like a permission problem, but ls - l gets this:

-rwxr-xr-x 1 www-data root 7550 Dec 13 02:01 cron.php

likely does not exist in in the container - you need to provide the file from “inside” the conatiner perspective which is /var/www/html/cron.php by default

Nice! That works! :slight_smile: Thank you!
But just the testing. If i put the command

docker exec --user www-data -it nextcloud php -f /var/www/html/cron.php --define apc.enable_cli=1

in crontab, it does not work. I tried crontab for user www-data as well as user root. Is there an easy way to access cron logs?
Anyway, i guess i need to look into the cron sidecar container.

I run it on the host, too. I described the procedure in my tutorial. I run the Nextcloud App as user 1004, if your instance run as root, you will need to edit the parameters.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.