Docker: NC17 php-fpm:alpine. Cron.php not properly running when using cron.sh as entrypoint

Created on 31 Oct 2019  Â·  32Comments  Â·  Source: nextcloud/docker

When using the cron container approach as specified here, the cron job does not appear to be running as it should, causing the application to display the following warning:

image

The feedback from the cron container's stdout is as follows:

crond:  line php -f /var/www/html/cron.php,
crond: wakeup dt=60,
crond: file www-data:,
crond:  line php -f /var/www/html/cron.php,
crond: wakeup dt=60,
crond: file www-data:,
crond:  line php -f /var/www/html/cron.php,
crond: user:www-data entry:*/15 * * * * php -f /var/www/html/cron.php,
100000000000000100000000000000100000000000000100000000000000,
111111111111111111111111,
11111111111111111111111111111111,

cron.php runs fine if invoked manually by logging into the container as www-data and executing php -f /var/www/html/cron.php.

question

All 32 comments

Don't know if I meet the same issue. I fixed it in Nextcloud:latest (apache) by building the image with supervisord to run cron. (official site: https://github.com/nextcloud/docker/tree/master/.examples)

But there's a problem. As the files&folders in "/var/www/html" (Nextcloud root dir) belong to "root:root" and they have 0755 properties, the default "www-data" crontab file in "/var/spool/cron/crontabs" may not have rights to write root's files&folders.

So I created "root" with the correct cron jobs and everything worked fine.

*/5 * * * * php -f /var/www/html/cron.php
* */6 * * * php -f /var/www/html/occ files:scan --unscanned --all 

The logs like these:

crond: wakeup dt=60
crond: file root:
crond:  line php -f /var/www/html/cron.php
crond:  job: 0 php -f /var/www/html/cron.php
crond:  line php -f /var/www/html/occ files:scan --unscanned --all
crond: file www-data:
crond:  line php -f /var/www/html/cron.php
crond:  job: 0 php -f /var/www/html/cron.php
crond: child running /bin/bash
crond: USER root pid 581 cmd php -f /var/www/html/cron.php

Sounds interesting. However, I am using the fpm-alpine variant.

Same here with apache image. Cron job does not run.

Same for fpm-alpine !

I had the same problem, I am using this compose filedocker/.examples/docker-compose/insecure/mariadb-cron-redis/fpm/.
The problem is execute cron.php in the container nextcloud-docker_apps as root works. But the problem is in the container running nextcloud-docker_cron encountered problems.
Do I leave the setting to ajax to avoid this error?

Hello all, I was having a similar issue to what is described here. My issue was that I had several volumes mounted in the app container that were not in the cron container. After fixing that issue cron is updating correctly and on time.

I had the same number of volumes on both containers. No avail. There is definitely an issue.

Running apk add busybox-suid inside the container fixed the problem for me. This issue probably only exists if you're using one of the alpine-Images.

Very interesing, @pestotoast. Will try this on my next build and report back. Thanks!

Sadly, it did not seem to work for me. I am back webcron, which works well.

Same error with Nextcloud 18.

I need system cron because News' app doesn't work with AJAX or Webcron.

Temporaly, I fixed this error creating a cron job at my Docker's host (Centos 8) with root with this statment:
*/5 * * * * docker exec --user www-data nextcloud php cron.php
The solution isn't nifty but at least now it's working and I my RSS feed is updating.

I hope this error will get fixed.

I'm trying to understand why webcron would not work if you ran it in a webcron container in the same stack. webcron is doing exactly the same thing:

  webcron:
    image: cw1900/docker-webcron
    restart: always
    environment:
      - INTERVAL_TIME=300
      - URL=https://my.nextclouddomain.com/cron.php

Hi again,

Note from News developers:

_Important: To enable feed updates you will need to enable either Nextcloud system cron or use an updater which uses the built in update API and disable cron updates._

Hmmm....you are right. This is a constraint from the News developers. I wonder why they do not allow webcron. It is the exact same cron.php call...

image

So, The Nextcloud's system cron with Docker should be fixed or this App , quite good by the way, won't work with container, because that "faster parallel updater" it's rather complicated to install through containers too.

I didn't! I'm gonna test it.

Thanks!

Did anyone manage to get it working yet? I can confirm that it is still broken in the nextcloud:18-apache image. I also need the cron job for updating my rss feeds..

Maybe @tilosp has an idea?

I am also using the docker-compose solution:

  nextcloud:
    image: nextcloud:18-apache
    ...
    volumes:
      - *nextcloud-data
      - *nextcloud-config
      - *nextcloud-apps

  cron:
    image: nextcloud:18-apache
    entrypoint:
      - /cron.sh
    volumes:
      - *nextcloud-data
      - *nextcloud-config
      - *nextcloud-apps

I deleted cron job for www-data and created cron job for root and it works now. The cron.php requires the owner of the config.php to run it. My config.php is owned by root because it was mount from windows file system. check your logs of cron container and see if there is complaints for config ownership.

@wyxls do you use docker on windows and bind mounted the /var/www/html from windows?

I tested https://github.com/kressh/nextcloud-news-updater/blob/master/Dockerfile and worked flawlessly updating my RSS feeds. I use docker compose for convenience, so this is my configuration:

news_updater:
image: kr3ssh/nextcloud-news-updater
container_name: news_updater
restart: always
environment:
- NEXTCLOUD_URL=https://nextcloud.${DOMAINNAME}
- NEXTCLOUD_ADMIN_USER=${ADMINUSER}
- NEXTCLOUD_ADMIN_PASSWORD=${ADMINPASS}
volumes:
- ${USERDIR}/docker/nextcloud/html:/var/www/html

Obviously, It doesn't fix the cron.sh entrypoint issue, but for my Nextcloud's small environment it's ok for me working with AJAX and this container.

Nice. Glad that worked for you.

@wyxls do you use docker on windows and bind mounted the /var/www/html from windows?

Well, Yes!

volumes:
- C:/Docker/nextcloud:/var/www/html
- D:/Docker/nextcloud/data:/var/www/html/data

At least that way can make the cronjob work properly on my Windows Server PC. I think it is just a property issue of cron job file. (root)

But running nextcloud within docker for windows seems to have some issues like file system property problems . Everything runs well except uploading & downloading & synchronizing large files (>1GB) or lots of small files.

When i remove my mounted volumes on windows (put it back to a volume inside the Hyper-V docker host VM), file operation become normal.

Don't know how to fix it so I'm using Seafile instead.

@wyxls do you use docker on windows and bind mounted the /var/www/html from windows?

Well, Yes!

volumes:
- C:/Docker/nextcloud:/var/www/html
- D:/Docker/nextcloud/data:/var/www/html/data

At least that way can make the cronjob work properly on my Windows Server PC. I think it is just a property issue of cron job file. (root)

But running nextcloud within docker for windows seems to have some issues like file system property problems . Everything runs well except uploading & downloading & synchronizing large files (>1GB) or lots of small files.

When i remove my mounted volumes on windows (put it back to a volume inside the Hyper-V docker host VM), file operation become normal.

Don't know how to fix it so I'm using Seafile instead.

I think I solved by delete cron job for www-data and create it for root.

after upgrade from 18 to 18.01. The cron job refused to work again. And the problem is I have to do a manual upgrade to the cron container. If you type "php occ status" in cron container, it will ask you to upgrade through web interface or occ upgrade. I can only do occ upgrade because I have already upgraded through web interface. I guess web interface only upgraded the main nextcloud container but not this cron container. After a quick “ php occ upgrade", it all worked again.

after upgrade from 18 to 18.01. The cron job refused to work again. And the problem is I have to do a manual upgrade to the cron container. If you type "php occ status" in cron container, it will ask you to upgrade through web interface or occ upgrade. I can only do occ upgrade because I have already upgraded through web interface. I guess web interface only upgraded the main nextcloud container but not this cron container. After a quick “ php occ upgrade", it all worked again.

The web updater only updates the php part. The cronjob in the NextCloud image is a seperate part from the main program.

Besides, you should pull the lastest image from nextcloud for upgrading version instead of updating within container. But it will disable the cron job because you must up the image again.

The most troublesome thing is that you must create cron job for root every time you rerun the NextCloud container to make cronjob work.

Same problem here. When executing within the nextcloud-cron container, it does not work at all. Not as www-data user, not as root.

It works when running within the nextcloud-app container.

As both share the same volumes, I don't know whats going on.
Docker OS is CentOS8.

NextCloud part of the compose file:

  app:
    image: nextcloud
    container_name: nextcloud-app
    restart: unless-stopped
    volumes:
      - /data/nextcloud/html:/var/www/html
      - /data/nextcloud/data:/var/www/html/data
    environment:
      - MYSQL_HOST=nextcloud-mariadb
      - VIRTUAL_HOST=cloud.example.com
      - LETSENCRYPT_HOST=cloud.example.com
      - [email protected]
      - REDIS_HOST=nextcloud-redis
      - TZ=Europe/Berlin
    env_file:
      - db.env
      - nextcloud.env
      - redis.env
    depends_on:
      - db
      - redis
    links:
      - db:clouddatabase
    networks:
      - nginx-proxy
      - nextcloud

  cron:
    image: nextcloud
    container_name: nextcloud-cron
    restart: unless-stopped
    volumes:
      - /data/nextcloud/html:/var/www/html
      - /data/nextcloud/data:/var/www/html/data
    environment:
      - TZ=Europe/Berlin
    entrypoint: /cron.sh
    depends_on:
      - app
      - db
      - redis

I was experiencing a similar issue with my NC 18.0.4 fpm-alpine based Compose setup.
Tried various suggestions here, as well as different methods recommended by Nextcloud, to no avail.

The problem seems to be caused by the www-data user not having the proper cron permissions, while root is not supposed to handle essential files like config.php.

The workaround that worked for me in the end is twofold:

1. Create a crontab for root

I created a ./config/cron/crontab file on my host, containing:

*/5 * * * * php -f /var/www/html/cron.php

2. Create a separate cron container

  • I'm mounting the cron file as root's crontab.
  • The cron container is the same as app, except for the entrypoint.

Below is the relevant excerpt from my docker-compose.yml.
(The & and * signs are _yaml node anchors_, duplicating the volumes and environment nodes for the app and cron containers, see the _Advanced components_ section on Wikipedia for more)

  app:
    container_name: nc-app
    image: nextcloud:fpm-alpine
    restart: always
    volumes: &webvols
      - nextcloud:/var/www/html
      - apps:/var/www/html/custom_apps
      - data:/var/www/html/data
      - config:/var/www/html/config
      - ${PWD}/config/cron/crontab:/var/spool/cron/crontabs/root:ro
    env_file:
      - ${PWD}/.db.env
    environment: &webenv
      - VIRTUAL_HOST=$NEXTCLOUD_VIRTUAL_HOST
      - MYSQL_HOST=db
      - REDIS_HOST=redis
      - NEXTCLOUD_TRUSTED_DOMAINS=$NEXTCLOUD_VIRTUAL_HOST
      - OVERWRITEPROTOCOL=https
    depends_on:
      - db
      - redis
    networks:
      - back

  cron:
    container_name: nc-cron
    image: nextcloud:fpm-alpine
    restart: always
    volumes: *webvols
    environment: *webenv
    depends_on:
      - db
      - redis
    networks:
      - back
    entrypoint: /cron.sh

Still, this is a workaround and it obviously shouldn't be needed.
They even explicitly remove root's crontab in the Dockerfile, so just putting it back feels redundant.
But so far it's been working smoothly and I haven't experienced any file permission issues as of yet.

Nextcloud 19.0.0

Can confirm this problem still exists.

Edit:
I have to retract my statement. Retested it today and it works without the root workaroung provided by aapit.

  cron:
    image: nextcloud:fpm
    container_name: cron_nextcloud
    restart: always
    volumes:
      - ${LOCAL_NEXTCLOUD_APPS}:/var/www/html/apps
      - ${LOCAL_NEXTCLOUD_CONFIG}:/var/www/html/config
      - ${LOCAL_NEXTCLOUD_DATA}:/var/www/html/data
      - ${LOCAL_NEXTCLOUD_HTML}:/var/www/html
    entrypoint: /cron.sh
    depends_on:
      - mariadb
      - redis
    networks:
      - proxy-tier

@aapit Thanks your working example!

The example does not use fpm-alpine though.

aapit s example does, mine does not. You can exchange the second line of my code to:

image: nextcloud:fpm-alpine

and it should run in the same way.

Was this page helpful?
0 / 5 - 0 ratings