-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Background jobs: Cron does not run #1695
Comments
Here is some info from docker image inspect for image versioning information: "Id": "sha256:df82fda354851c092a2e95bb49189231931c357c36ab03a4ec3c19fdd64c4925", |
The background cron should be run in a separate container
|
That could work but if it is starting a while new container, that sounds like a bit more RAM just to run Cron.php. also seeing two containers sharing the volume seems odd. Since you could have file IO errors. |
so few ways to use the cron is,
|
That's the recommended way in the examples and no proplem with sharing the same volume because it's only calls the cron file and about ram it uses 38mb of ram so not really a problem so don't worry and spin that extra cron container Edit.. |
@martadinata666 , I use the host to push a docker exec, and it works, and cron initiates sending the command to the container. |
But it's documented in the official examples here |
@kemoantemo , |
I get you but any new user should follow the examples of the official docker so where is the problem? Maybe it's not in the documentation of nextcloud because next cloud have a lot of deploy methods so you should check the examples of the method you going to use and don't worry from the cron container it's not fully nextcloud container it doesn't run nextcloud instance it just run a cron process that calls cron.php every 5 minutes so it's pretty good and easy to applicate solution. you can use the supervisored to run nextcloud and cron from same container but it's really almost the same because after all it's the same PID so just use the official examples and don't worry |
everyone got personal preferences, in my case i rather not modify host so i create custom image with added supervisor to run cron and apache in parallel. Because i also need additional job like full text search, and preview generator, and pretty messed up on upgrade as it get overwritten cmiiw |
The NC docker docs just mention cron briefly, pointing to the examples:
Here is where cron is defined in the examples This would be the correct way to do it with docker-compose*. Containers should be a single process to allow logs and error handling to make sense. Since almost every(?) instance needs cron, maybe it should be more prominent in the docs? *(In Kubernetes you can use a |
Sorry to revive this a month later, but I am also facing issues with my Cron set-up. My docker-compose.ymlversion: '2'
services:
db:
image: mariadb:10.5
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=[pw]
- MYSQL_PASSWORD=[pw]
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
redis:
image: redis:alpine
restart: always
app:
image: nextcloud
restart: always
ports:
- 80:80
depends_on:
- db
links:
- redis
volumes:
- ./config:/var/www/html/config
- ./apps:/var/www/html/custom_apps
- /nextcloud-data:/var/www/html/data
environment:
- MYSQL_PASSWORD=[pw]
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
- SMTP_HOST=mail.me.eu
- SMTP_SECURE=tls
- SMTP_PORT=587
- [email protected]
- SMTP_PASSWORD=[pw]
- MAIL_DOMAIN=me.eu
- MAIL_FROM_ADDRESS=system
- TRUSTED_PROXIES=192.xxx.xxx.xx
- TRUSTED_DOMAIN=cloud.me.eu
- REDIS_HOST=redis
cron:
image: nextcloud
restart: always
volumes:
- ./config:/var/www/html/config
- ./apps:/var/www/html/custom_apps
- /nextcloud-data:/var/www/html/data
entrypoint: /cron.sh
depends_on:
- db
- redis Despite copying the proposed cron container description - except the volumes as I'm only using more specific ones rather than just the generic I asked support on the forum but unfortunately the answers provided there don't really get me much further. On the one hand I'm hoping to get feedback on my situation. On the other hand I'm here to support the call for more documentation/explanation on using docker (more than only an example file that doesn't explain anything and isn't of much help when debugging). |
@keunes the /var/www/html is an essential for not just cron but also for upgrading you should have it first then take every custom data or config as you want after so try to make a volume for /var/www/html |
@keunes try setting the MYSQL variables in the environment of the cron container as well. They're not specifying any in the example, but I am going to guess that is because they are using defaults. |
@danieljkemp it's getting it from the config file no need to he just need to mount the /var/www/html |
You're amazing, this worked! Just for my understanding: why is it that adding this 'parent' volume fixed it? Which directories/files are there that cron needs (or that the app needs to know that cron is running)? I think it would be helpful to mention in the docs (docker Readme) what you told me also, namely that the parent folder must be there, and that child directories may be specified after. I see now that it is mentioned Persistent data somewhat implicitly, but not mentioned in the Docker compose section. I'll prepare a PR with some suggested changes later on. Also, another question for my understanding: what happens behind the scenes when mounting a parent and then some child directories? On the first run with the global/first volume (when the
|
The essential thing is the Assume you had |
The crazy part is that You'd expect to just need to mount the config and data directories into the app containers (main and cron included), and this is indeed how other applications work, but no, the the nextcloud containers references that volume (the one containing just copied source) directly. |
The reason that cron didn't work is that the /var/www/html is just empty because you didn't call the entrypoint.sh which checks the version of your nextcloud and if it's existing or not then copy from /usr/src/nextcloud as i remember not sure. So that does happen only if you started the entrypoint.sh so that you don't have problems with the app container but it's surely slow at starting because it copies everytime it starts and for the cron container it doesn't find the php source of nextcloud at /var/www/html so it can't run. I hope I managed to describe it in a good way. |
Thanks all for the help and explanations (and sorry for replying only now). I managed to get it working! I think indeed the trick was to add the volume |
Thanks for that info, it answered my question, hope it helps someone else too. I feel, from the current example, if it only depends on DB, then we gotta give it all the environment parameters! Which is not really great thing to do. |
and I did a pull request #1710 for it but it doesn't work with stack so they didn't implement it |
Hello to all, Here is my portainer stack (I think it's nearly the same as the docker-compose.yml): `services: redis: app: cron: networks: |
It's fantastic: after posting my comment I've rebooted my Diskstation and now nextcloud cron works fine. :) |
Personally, I think docker exec is a better way, because is does not requires to change official nextcloud docker image, and automatic upgrade is possible. |
mine doesn't work. i check the container log for the cron service and here's what i found:
for reference, this is my docker-compose:
|
The nextcloud volumes and cron volumes must inline |
already did
|
The config? The data? The custom? |
so i have to add these too?
|
Yes, because |
yes, finally it works. thank you |
for me cron is not working too, i don't know what to do anymore. `version: '3' volumes: networks: services: app:
cron: redis: |
Found this page while looking up the same issue. After much trial and error, I found there is no need for an extra Container just to run Cron. The host OS is absolutely fine to run this task. However, what I found does contradict the Nextcloud documentation a bit. Running cron through crontab -u www-data -e never quite worked for me. That could be a "me" problem as I missed something. Solution for me: My host OS /etc/crontab Since this, I have had the little green light of joy showing on the web GUI for NC |
here is my yml file compose , please help me to run cron yml version: '3.7' networks: volumes: services: ports:- 27017:27017
nextcloud: Thanks a lots |
Dear all, you can build your image using below dockerfile @beryl03 maybe you can try this ARG NC_VERSION
FROM nextcloud:${NC_VERSION}
RUN touch /var/log/cron.log
CMD /cron.sh >> /var/log/cron.log 2>&1 & php-fpm
Then docker-compose example below: version: '3.9'
services:
nextcloud:
# "context" and "dockerfile" fields have to be under "build"
build:
context: .
dockerfile: <Directory>/Dockerfile |
I would use cron:
image: nextcloud:${VERSION}
volumes_from:
- nextcloud
entrypoint: /cron.sh |
My solution:
nc-autocron.sh:
|
I'm getting "/bin/bash: line 1: /nc-autocron.sh: Permission denied" |
Did you |
thx |
now there is anothe problem:
|
Well it seems you aren't setting the |
I have found better settings from source code. please ref: use the supervisord is stable than modify dockerfile entrypoint. @J0WI Maybe this issue can be closed? |
installed nc. postgre. redis through compose. all work, but try cron from host and see a strange error: /usr/bin/docker exec -u www-data nextcloud php -f /var/www/html/cron.php Can somebody help? im stuck . in past i use this in NC 25, but on fresh install it dont work. containers connects ok, all functions work, but cron - no My compose file: services: postgres-nextcloud: redis-nextcloud: |
This is more or less a duplicate of #627. |
working solution Here is a working solution assuming you've installed cron
|
I almost tried what was suggested in this thread, but this is what worked for me. I have Nextcloud running in a docker container, so I wanted to try making it work without spinning a separate container just to execute the cron.php file. On the system's root crontab, I added this line and that's it. I didn't need to adjust anything else. My system is executing the */5 * * * * /usr/bin/docker exec -u www-data nextcloud php cron.php @almgwary's way works if you have nextcloud running not inside docker container. But since the nextcloud's official container doesn't come with crontab, I have to use the system's crontab and docker exec command to achieve this. |
maybe I'm not getting it. but shouldn't nextcloud docker image bring its own predefined cron setting? why do I have to find out that my jobs are not running? and trigger the cron.php from outside? this is not how it should be! I'm disappointed meanwhile about the amount of effort that I had to put into my NC installation to make it work |
This method also works for me but the command needs about 14 minutes in order to complete in my Raspberry Pi. One of the CPU cored is at 100% during this time and the temperature rises. If I run the command every 5 minutes, this means that 3 instances of the command are going to be running simultaneously at some point (occupying 3 CPU cores). Is this normal? EDIT: It seems like after running |
This worked for me updating the entrypoint to /cron.sh did really work I tried many other things but nothing worked. adding cron.sh worked. |
Tag: latest (2022/02/04)
When trying to setup Cron as the background job, it seems it cannot work without a lot of work on top of the image
Missing:
Packages: Cron (and dependencies)
Service: Something to run Crontab jobs
Settings to Reproduce:
Mitigation:
Mitigation is to setup Cron on Host and run "docker exec -u 33 -t nextcloud-app php -f /var/www/html/cron.php" (www-data UID = 33)
Proposed Solution:
OR
The text was updated successfully, but these errors were encountered: