Cron job not running using official docker apache example

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can. :heart:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 30.0.5.1
  • Operating system and version (e.g., Ubuntu 24.04):
    • Docker image (apache) on Debian 12
  • Web server and version (e.g, Apache 2.4.25):
    • 2.4.62
  • PHP version (e.g, 8.3):
    • 8.2.27
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Custom 30.0.4 docker image using official cron example for apache base
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • no

Summary of the issue you are facing:

Cannot get the official cron example (apache docker image) running in my nextcloud instance.

Steps to replicate it (hint: details matter!):

  1. Create a fresh docker image “nextcloud:test” using the official examples
  2. Used the following docker-compose.yml. I wasn’t quite sure if the cron jobs were sought under root or www-data, so I put both.
services:
  app:
    image: nextcloud:test
    restart: unless-stopped
    ports:
      - 8089:80
    volumes:
      # Set timezone same as host
      - /etc/localtime:/etc/localtime:ro
      - ./www_html:/var/www/html
      - ./crontab:/var/spool/cron/crontabs/www-data
      - ./crontab.root:/var/spool/cron/crontabs/root

  1. The two crontab files “crontab” and “crontab.root” contain
* * * * * date >> /tmp/cron.txt
* * * * * echo "I am root" >> /tmp/cron.txt

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

The container logs show "crond: crond (busybox 1.35.0) started, log level 8.

Initializing nextcloud 30.0.5.1 ...
New nextcloud instance
Next step: Access your instance to finish the web-based installation!
Hint: You can specify NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD and the database variables _prior to first launch_ to fully automate initial installation.
Initializing finished
=> Searching for scripts (*.sh) to run, located in the folder: /docker-entrypoint-hooks.d/before-starting
2025-01-30 10:55:07,063 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
crond: crond (busybox 1.35.0) started, log level 8
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.2. Set the 'ServerName' directive globally to suppress this message
[Thu Jan 30 10:55:08.249311 2025] [mpm_prefork:notice] [pid 129:tid 129] AH00163: Apache/2.4.62 (Debian) PHP/8.2.27 configured -- resuming normal operations
[Thu Jan 30 10:55:08.249850 2025] [core:notice] [pid 129:tid 129] AH00094: Command line: 'apache2 -D FOREGROUND'

When I exec into container and list /tmp I do not see what is expected from the cron jobs that were configured - cron.txt with either the ‘date’ or the text “I am root” written into it. There is no cron.txt present under /tmp no matter how long I wait.

$ docker exec -it test-app-1 bash

root@7a11f36a5527:/var/www/html# date
Thu Jan 30 11:01:38 PST 2025

root@7a11f36a5527:/var/www/html# ls -al /tmp
total 8
drwxrwxrwt 1 root root 4096 Jan 30 10:55 .
drwxr-xr-x 1 root root 4096 Jan 30 10:54 ..

root@7a11f36a5527:/var/www/html# date
Thu Jan 30 11:12:21 PST 2025

root@7a11f36a5527:/var/www/html# ls -al /tmp
total 8
drwxrwxrwt 1 root root 4096 Jan 30 10:55 .
drwxr-xr-x 1 root root 4096 Jan 30 10:54 ..

The process list shows that supervisord and busybox crond are running

root@aab600037ee6:/var/www/html# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  1 11:08 ?        00:00:00 /usr/bin/python3 /usr/bin/supervisord -c /supervisord.conf
root          47       1  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
root          48       1  0 11:08 ?        00:00:00 busybox crond -f -L /dev/stdout
www-data      59      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      60      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      61      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      62      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
www-data      63      47  0 11:08 ?        00:00:00 apache2 -DFOREGROUND
root          64       0  2 11:08 pts/0    00:00:00 bash
root          70      64  0 11:08 pts/0    00:00:00 ps -ef

I have seen in other posts recommending setting up cron in the host environment. That’ll be my last resort but I would like to keep all of this self-contained in the NC deployment so I can easily move it to another system as needed. It’s a small personal instance so it’s fine that my deployment is running more than a single service.

Can someone help point me in the right direction? Where can I look to troubleshoot why the simple cron jobs aren’t firing? Again, I wasn’t sure if the cronjob was expected under root or www-data (the latter I think) but provided but to cover all bases.

Appreciate the help!

I haven’t personally tested the supervisor method in a while, but the one that I typically suggest is the other one, which doesn’t require any image building/customization and is still fully self-contained in your Compose file - example:

Are you trying to run other custom cron jobs other than Nextcloud’s cron.php?

P.S. If you overwrite /var/spool/cron/crontabs/www-data in the container you’re effectively deleting the existing entry that is shipped in the image.

Sorry about the delay. Life happened and I forgot about this thread.

I haven’t overwritten /var/spool/cron/crontabs/www-data file. Well, technically, yes but the content retains what’s there by default and adds another entry.

*/5 * * * * php -f /var/www/html/cron.php
*/5 * * * * date >> /tmp/cron.txt

The 1st line is what’s there out of the box. I added just a simple date output to a temp file as a test.

The test cront.txt file never gets created. I’m just using the vanilla image and create a new image on top of that using the example files at docker/.examples/dockerfiles/cron/apache at master · nextcloud/docker · GitHub

I’m lost as to where I can go next. If this fails, I guess I can fall back to using the hosts cron job to schedule things like preview generation, file scanning newly added files (file system, not through webUI), etc.

Any clues as to why the simple cron job isn’t working would be very much appreciated.

Can you add 2>&1 after the .txt
And after run have you look again to this file.

I tried adding 2>&1 for the second cron job entry but no dice.

Can you create the file manually first and set the correcr rights, i think there is some problem with rights.
Can you explain what do you want at the end what is the goal?

A lot of my content is synced up to external storages bypassing the Web UI. As a result, the content isn’t indexed or listed in the UI. I also want to pre-generate image preview thumbnails ahead of time. Those are just two things that come to mind. I want to have the two jobs running a couple of times a day.

Unless I’m mistkane, Nextcloud won’t be able to update these things, especially when content is updated outside of the user interface. That’s why I would like to configure these custom jobs. By the way, I also have the “Background jobs” configuration set to “Cron (Recommended” option instead of AJAX or Webcron.

I tried creating the cron.txt file the job was supposed to write into. Again, no luck. It’s location is in /tmp so it should not have any problems writing to it in the first place.

So you have created the file and your cron looks so

*/5 * * * * date >> /tmp/cron.txt 2>&1

And there is absolut no content in the file?

Yep. The file /var/spool/cron/crontabs/www-data has

*/5 * * * * php -f /var/www/html/cron.php
*/5 * * * * date >> /tmp/cron.txt 2>&1

and after over 10 minutes nothing is written to that file.

It almost feels like the busybox crond process isn’t running properly or running the crontabs for www-data.

Why you not edit via sudo -u www-data crontab -e

The official docker image for Nextcloud appears to be running Debian (bookworm) but it doesn’t have crontab. There is no such CLT

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