Cron doesn't execute cron.php

Hi again,

The script cron.php doesn’t execute itself … and I have no clue why because when I try to launch the task as www-data manually I don’t have any error message and the UI tells me that the task ran for the last time a few seconds ago.

I tried replacing php by php-cli, I also tried to add the path to PHP and chmod +x cron.php just in case, no change. Cron just don’t execute any task. AJAX works … but that’s all.

OS: Ubuntu 18.04.1 LTS
Docker: 18.09.1
Docker-Compose: 1.23.2, build 1110ad0
Image: Nextcloud:latest (15.0.2) default install

My docker-compose.yml:

version: '3.5'

services:

  proxy:
    image: jwilder/nginx-proxy:alpine
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
    container_name: nextcloud-proxy
    networks:
            nextcloud:
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./proxy/conf.d:/etc/nginx/conf.d:rw
      - ./proxy/vhost.d:/etc/nginx/vhost.d:rw
      - ./proxy/html:/usr/share/nginx/html:rw
      - ./proxy/certs:/etc/nginx/certs:ro
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: unless-stopped

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nextcloud-letsencrypt
    depends_on:
      - proxy
    networks:
            nextcloud:
    volumes:
      - ./proxy/certs:/etc/nginx/certs:rw
      - ./proxy/vhost.d:/etc/nginx/vhost.d:rw
      - ./proxy/html:/usr/share/nginx/html:rw
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: unless-stopped

  db:
    image: mariadb
    container_name: nextcloud-mariadb
    networks:
            nextcloud:
    volumes:
      - db:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_ROOT_PASSWORD=*********
      - MYSQL_PASSWORD=*********
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=ncuser
    restart: unless-stopped

  app:
    image: nextcloud:latest
    container_name: nextcloud-app
    networks:
            nextcloud:
    depends_on:
      - letsencrypt
      - proxy
      - db
    volumes:
      - nextcloud-data:/var/www/html
      - /etc/localtime:/etc/localtime:ro
    environment:
      - VIRTUAL_HOST=cloud.mydomain.tld
      - LETSENCRYPT_HOST=cloud.mydomain.tld
      - LETSENCRYPT_EMAIL=administrator@mydomain.tld
    restart: unless-stopped

volumes:
  nextcloud-data:
          external: true
  db:

networks:
  nextcloud:
          name: my-network

perhaps /usr/bin/php would be better. (or where ever php is installed.) cron jobs don’t have normal env settings.

As I said, I tried adding the path and no change at all unfortunately.

so how do you run php cron.php ?
inside the container or using docker exec?

Inside the Docker actually. Do I have to use the host cron with docker exec ?
As I said, when I execute the command manually from inside the Docker it works.

Have you checked whether the time setting in the docker container is correct? It could be, that the crontab is not executing the job due to time inconsistency.

Whether you execute the cron command from within the container or via docker exec, it always uses the container crontab. You should never use the host crontab to do something in the docker container.

why?

at least this works in the hosts crontab:

docker exec --user www-data nextcloud php -f cron.php > /dev/null 2>&1
2 Likes

I don’t understand why you shouldn’t execute a cron task from the host since you can put a docker-exec command.

The time is right, the same as the host as you can see in my docker-compose.yml file.
And since the task should execute itself in a 15 minutes interval, even if the time wasn’t right it should be OK since 15 minutes are always 15 minutes, no ?

Just to clarify, my last sentence regarding the “execution of cron tasks via the host towards the docker container” was unwell chosen.

To rectify my last sentence, yes you can use the host crontab with the docker exec command (just like @Reiner_Nippes mentioned in his last post). In fact I thought about it a little more and tested it yesterday and would even agree, that this is the better solution.

@Xanarkan I mentioned the time as a possible cause because I had this on a clients machine once. They had a weird timezone setup and the date was always set in the past and their cron jobs were not running as well.

Try setting up a cron job with @Reiner_Nippes example on your host and monitor the /var/log/syslog for cron entries and see, if it gives you any info/warning/error messages. As you said yourself, you can run the command from within the container (calling the cron.php) without any errors, so there must be something crontab is tripping over.

Ho, okey I understand better what you said.
Concerning the time, seems that’s the same within the docker and on the host.

root@1f0fd54c00c6:/var/www/html# date
Wed Jan 30 15:56:31 UTC 2019
root@1f0fd54c00c6:/var/www/html# exit
exit
root@raging-server:# date
mercredi 30 janvier 2019, 15:56:41 (UTC+0000)