Unable to run cron (scan all files every 5 mins)

Hi I have installed docker desktop on my windows 11 machine. I am using the following docker compose file

version: ‘3.7’

services:
nextcloud:
image: nextcloud
container_name: nextcloud-app
restart: always
ports:
- 8080:80
volumes:
- E:/nextcloud/data:/var/www/html/data
- E:/nextcloud/config:/var/www/html/config
- E:/nextcloud/apps:/var/www/html/custom_apps
environment:
- MYSQL_HOST=db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextclouduser
- MYSQL_PASSWORD=your_password
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=admin
depends_on:
- db

db:
image: mysql:5.7
container_name: nextcloud-db
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root_password
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextclouduser
- MYSQL_PASSWORD=your_password
volumes:
- db_data:/var/lib/mysql

volumes:
db_data:

Next cloud is all up and running and I have set basic settings to cron (admin settings > basic settings)

Using cmd I have navigated to the container using

docker exec -it nextcloud-app bash

followed by crontab -e

then using nano I have added

*/5 * * * * php /var/www/html/occ files:scan --path=“/var/www/html/config”

I have left this running however the new files which I manually added to my e drive are not showing up. When I run the command service cron status it states that cron service is running but it doesn’t appear to be working. Any idea how to resolve this?

hi @NC_user123 welcome to the community :handshake:

Please use search - this issue was often discussed already e.g. Nextcloud Docker Container - best way to run cron job

the app container doesn’t execute cron tasks itself. you need another container running cron, please review

1 Like

Hi,

please have a look at my Nextcloud setup, I just uploaded it for you here:

This setup might be sketchy, but works fine for me :slight_smile:

You can change the crontab file and add another cronjob as needed, for example:

*/5 * * * * sudo -u www-data /var/www/html/occ files:scan --path=“/var/www/html/config”

Why would you want to scan the config folder tho?

Joshua

1 Like

Thank you both for your help and sorry if my reply is later then expected.

I am very lost. I am not much of a linux user and new to compose files and of course NC :grin: so I am learning things as I go along. I have made adjustments to the docker compose file see below

version: '3.7'

services:
  nextcloud:
    image: nextcloud
    container_name: nextcloud-app
    restart: always
    ports:
      - 8080:80
    volumes:
      - E:/nextcloud/data:/var/www/html/data
      - E:/nextcloud/config:/var/www/html/config
      - E:/nextcloud/apps:/var/www/html/custom_apps
    environment:
      - MYSQL_HOST=db
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextclouduser
      - MYSQL_PASSWORD=your_password
      - NEXTCLOUD_ADMIN_USER=admin
      - NEXTCLOUD_ADMIN_PASSWORD=admin
    depends_on:
      - db

  db:
    image: mysql:5.7
    container_name: nextcloud-db
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root_password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextclouduser
      - MYSQL_PASSWORD=your_password
    volumes:
      - db_data:/var/lib/mysql

  cron:
    image: nextcloud
    container_name: nextcloud-cron
    restart: always
    entrypoint: /cron.sh
    volumes:
      - E:/nextcloud/data:/var/www/html/data
      - E:/nextcloud/config:/var/www/html/config
      - E:/nextcloud/apps:/var/www/html/custom_apps
    environment:
      - MYSQL_HOST=db
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextclouduser
      - MYSQL_PASSWORD=your_password
      - NEXTCLOUD_ADMIN_USER=admin
      - NEXTCLOUD_ADMIN_PASSWORD=admin
    depends_on:
      - db

volumes:
  db_data:

Hopefully this is ok. I have rerun the container and it all looks to be working. However when I look into nextcloud-cron every 5 minutes I see the following error in the logs

Could not open input file: /var/www/html/cron.php

I have tried navigating to the file to see if it is there by

docker exec -it nextcloud-app bash

this takes me to /var/www/html# and when I tap ls I can see the cron.php file. Any idea why docker desktop is returning this error and how I can get it resolved?

as you are troubleshooting the cron container I would examine from there. Although you use same volume mounts and the should be no difference I would still use docker exec -it nextcloud-cron ls -al /var/www/html/cron.php… the file should be there and has 640 permissions in my system (owner by default 33:33 or www-data:www-data).

it’s not related to the problem but I would make cron depend on nextcloud rather on db

Thanks wwe

I ran the command exec -it nextcloud-cron ls -al /var/www/html/cron.php
and it returned no file or directory existed. Going one folder back I can see the following

docker exec -it nextcloud-cron ls -al /var/www/html/
total 8
drwxrwxrwt 5 www-data root 4096 Aug 31 16:33 .
drwxrwxr-x 1 www-data root 4096 Aug 30 23:31 …
drwxrwxrwx 1 www-data www-data 4096 Aug 26 18:52 config
drwxrwxrwx 1 www-data www-data 4096 Aug 26 16:53 custom_apps
drwxrwx— 1 www-data www-data 4096 Aug 27 13:15 data

Any idea how to get add this again? Not sure if I can obtain the file from somewhere - download it maybe?

Thanks again

your Nextcloud and cron container are supposed to be identical… ideally your Nextcloud container holds the data… if not just do

  • docker compose down
  • docker compose pull (maybe with force)
  • docker compose up

this should result in clean fresh images downloaded from Docker Hub and only your files are mounted into this fresh conatiner.

I tried this but now when I navigate to my localhost it throws a server error. I will try and delete everything and start again. I noticed in docker desktop the SQL image is 9 months old so maybe it is looking at stale information.

The above is the problem. The real issue is that your volume configuration isn’t appropriate on your app container. So it also won’t work for your cron container.

You need to have a volume for /var/www/html. Please see the docs: GitHub - nextcloud/docker: ⛴ Docker image of Nextcloud

Also, having everything in separate volumes like that is fine, but is is more complicated. It doesn’t appear you’re placing them in separate places so you’re likely making things unnecessarily complicated for yourself, without any apparent benefit for your use case.

1 Like

Thanks JTR, What would you recommend I change this to? I have tried a single line (volumes:

  • E:/nextcloud/data:/var/www/html) so the compose file looks like this:

version: ‘3.7’

services:
nextcloud:
image: nextcloud
container_name: nextcloud-app
restart: always
ports:
- 8080:80
volumes:
- E:/nextcloud/data:/var/www/html
environment:
- MYSQL_HOST=db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextclouduser
- MYSQL_PASSWORD=your_password
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=admin
depends_on:
- db

db:
image: mysql:5.7
container_name: nextcloud-db
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root_password
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextclouduser
- MYSQL_PASSWORD=your_password
volumes:
- db_data:/var/lib/mysql

cron:
image: nextcloud
container_name: nextcloud-cron
restart: always
entrypoint: /cron.sh
volumes:
- E:/nextcloud/data:/var/www/html
environment:
- MYSQL_HOST=db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextclouduser
- MYSQL_PASSWORD=your_password
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=admin
depends_on:
- db

volumes:
db_data:

In the cron logs I see

Warning: require_once(/var/www/html/lib/versioncheck.php): Failed to open stream: No such file or directory in /var/www/html/cron.php on line 45

and

Fatal error: Uncaught Error: Failed opening required ‘/var/www/html/lib/versioncheck.php’ (include_path=‘.:/usr/local/lib/php’) in /var/www/html/cron.php:45

So it looks as though I don’t have something quite right?

Further to this I have tried updating the cron job

docker exec -it nextcloud-cron bash

followed by crontab -e

then using nano I have added

*/5 * * * * php /var/www/html/occ files:scan --path=“/var/www/html/config”

In the logs now I am seeing the following:

2024-09-05 15:20:00 crond: USER root pid 806 cmd php /var/www/html/occ files:scan --path=“/var/www/html/config”
2024-09-05 15:20:00 crond: USER www-data pid 807 cmd php -f /var/www/html/cron.php
2024-09-05 15:20:02 Console has to be executed with the user that owns the file config/config.php
2024-09-05 15:20:02 Current user id: 0
2024-09-05 15:20:02 Owner id of config.php: 33
2024-09-05 15:20:02 Try adding ‘sudo -u #33’ to the beginning of the command (without the single quotes)
2024-09-05 15:20:02 If running with ‘docker exec’ try adding the option ‘-u 33’ to the docker command (without the single quotes)

Any help would be greatly appreciated. This is the last task before I think I can really start to use NC.

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