rcdailey / nextcloud-cronjob Goto Github PK
View Code? Open in Web Editor NEWA simple container to run cron.php in your Nextcloud docker container
Home Page: https://hub.docker.com/r/rcdailey/nextcloud-cronjob/
A simple container to run cron.php in your Nextcloud docker container
Home Page: https://hub.docker.com/r/rcdailey/nextcloud-cronjob/
At the moment, it seems like the ARM architecture is not supported by the image currently on Docker Hub. It would be great if support could be added, for I would like to use it on my Raspberry Pi.
Hey :)
First of all thank you for creating this Docker image. I was looking for something like this for ever!
I just have the issue that crond is not starting. see log:
Will search for Nexcloud container as a Docker Compose service
Project: nextcloud, Service: app
Found Nextcloud container with ID 623030c27720
Chosen shell "bash" was found in the Nextcloud container
Starting crond
after that the log file ends.
How can i fix this?
Hi,
Sorry to bother with what seems like such an easy fix, but I've tried everything and gone through the other issues. The solutions provided doesn't seem to rectify the problem for me.
I am getting the following error described above in the cronjob logs.
Will search for Nexcloud container as a Docker Compose service
Project: nextcloud, Service: nextcloud
ERROR: Unable to find the Nextcloud container
Below is my config for Nextcloud in docker-compose.yml file:
nextcloud:
<<: *common-keys-apps
image: nextcloud:stable
container_name: nextcloud
hostname: nextcloud
#ports:
# - 3000:80
# Persistent volumes with bind mounts to easily move/backup data
volumes:
- $DOCKERDIR/appdata/nextcloud/html:/var/www/html
- $DOCKERDIR/appdata/nextcloud/apps:/var/www/html/custom_apps
- $DOCKERDIR/appdata/nextcloud/config:/var/www/html/config
- $DOCKERDIR/appdata/nextcloud/data:/var/www/html/data
# Environment (internal to the container) variables to simplify setup
environment:
# Redis host name (container_name)
- REDIS_HOST=$NEXTCLOUD_REDIS__HOST
- NEXTCLOUD_TRUSTED_DOMAIN=files.$DOMAINNAME_CLOUD_SERVER
- TRUSTED_PROXIES=192.168.90.254/24
labels:
- "traefik.enable=true"
## HTTP Routers
- "traefik.http.routers.nextcloud-rtr.entrypoints=https"
- "traefik.http.routers.nextcloud-rtr.rule=Host(`files.$DOMAINNAME_CLOUD_SERVER`)"
- "traefik.http.routers.nextcloud-rtr.tls=true"
- “traefik.http.routers.nextcloud-rtr.middlewares=cloud,cloud-dav”
## Middlewares
- "traefik.http.routers.nextcloud-rtr.middlewares=chain-nextcloud@file"
## HTTP Services
- "traefik.http.routers.nextcloud-rtr.service=nextcloud-svc"
- "traefik.http.services.nextcloud-svc.loadbalancer.server.port=80"
And for cron-job config in the same file:
cron:
# <<: *common-keys-core
image: rcdailey/nextcloud-cronjob
restart: always
network_mode: none
depends_on:
- nextcloud
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/localtime:/etc/localtime:ro
environment:
- NEXTCLOUD_CONTAINER_NAME=nextcloud
- NEXTCLOUD_PROJECT_NAME=nextcloud
- NEXTCLOUD_CRON_MINUTE_INTERVAL=5
#- DEBUG
Thank you for your time.
Here my Yaml
version: '3.8'
services:
db:
image: mysql:5.7.31
command: mysqld --sql-mode=NO_AUTO_VALUE_ON_ZERO
environment:
- MYSQL_ROOT_PASSWORD=xxxx
- MYSQL_PASSWORD=xxxx
- MYSQL_DATABASE=xxxxxxx
- MYSQL_USER=xxxxxxxxx
volumes:
- ${WEBAPP_STORAGE_HOME}/mysql:/var/lib/mysql
restart: always
app:
image: nextcloud:18.0.9
ports:
- 80:80
environment:
- MYSQL_DATABASE=xxxxxxxx
- MYSQL_USER=xxxxxxx
- MYSQL_PASSWORD=xxxxxx
- MYSQL_HOST=db
- NEXTCLOUD_TRUSTED_DOMAINS=mydomain.net
- NEXTCLOUD_DATA_DIR=/var/www/html/data/NextCloudData
restart: always
volumes:
- CloudData:/var/www/html/data/NextCloudData
- ${WEBAPP_STORAGE_HOME}/nextcloud/config:/var/www/html/config
- ${WEBAPP_STORAGE_HOME}/nextcloud/apps:/var/www/html/custom_apps
cron:
image: rcdailey/nextcloud-cronjob
restart: always
network_mode: none
depends_on:
- app
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/localtime:/etc/localtime:ro
environment:
- NEXTCLOUD_EXEC_SHELL_ARGS=-xc
- NEXTCLOUD_CONTAINER_NAME=app
- NEXTCLOUD_EXEC_SHELL=sh
I get
Container logs from xxxxxx_cron_0_3e7a4656 = 2020-10-07T20:19:27.777456415Z Container Name: app Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ERROR: Unable to find the Nextcloud container Container Name: app
Hello!
I have just started using your unRAID app with the official Nextcloud docker container, and for some reason I am getting this error when it tries to run the script. The cron.php
file does exist inside that folder and is properly mapped too.
-------------------------------------------------------------
Executing Cron Tasks: Wed Feb 28 13:35:00 UTC 2024
-------------------------------------------------------------
> Nextcloud Container ID: 3cbcdb301c80
> Running Script: ./run-cron-php.sh
Could not open input file: /var/www/html/cron.php
> Done
Initially I was getting
-------------------------------------------------------------
Executing Cron Tasks: Wed Feb 28 13:25:00 UTC 2024
-------------------------------------------------------------
> Nextcloud Container ID: 3cbcdb301c80
> Running Script: ./run-cron-php.sh
Cannot write into "config" directory!
This can usually be fixed by giving the web server write access to the config directory.
But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.
See https://docs.nextcloud.com/server/28/go.php?to=admin-config
> Done
But I solved it by giving rw perms to www-data.
I don't really understand why it cant execute it now. I've now gone as far as giving rwx perms to owner, group, and other.
...
I tried to setup nextcloud-cronjob with nextcloud:19-fpm-alpine image and got this error:
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: "bash": executable file not found in $PATH": unknown
I think this is because Alpine OS uses sh instead of bash. It would be great to have this supported.
There seems to be an issue with the grep.
We can have multiple instances on the same node, we still need to pick only one.
See logs bellow, the nextcloud_exec_no_shell
command is executed with two ID: 9e19821d2d60 552ed77d1b59
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + source /nextcloud-exec.sh
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + [[ -z nextcloud_app.* ]]
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + [[ -n '' ]]
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + echo 'Container Name: nextcloud_app.*'
nextcloud_cron.1.z4e0bdszbg6h@srv2 | Container Name: nextcloud_app.*
nextcloud_cron.1.z4e0bdszbg6h@srv2 | ++ /find-container.sh
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + containerId='9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2 | 552ed77d1b59'
nextcloud_cron.1.z4e0bdszbg6h@srv2 | Found Nextcloud container with ID 9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2 | 552ed77d1b59
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + [[ -z 9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2 | 552ed77d1b59 ]]
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + echo 'Found Nextcloud container with ID 9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2 | 552ed77d1b59'
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + nextcloud_exec_no_shell '9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2 | 552ed77d1b59' sh -c 'command -v "bash"'
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + echo 'ERROR: Shell "bash" does not exist in the Nextcloud container'
nextcloud_cron.1.z4e0bdszbg6h@srv2 | + exit 1
nextcloud_cron.1.z4e0bdszbg6h@srv2 | ERROR: Shell "bash" does not exist in the Nextcloud container
When starting the docker container it’s starting properly and everything loads properly, even setting up crontab, so entry point.sh is doing everything right, but it doesn’t run cron-tasks.sh if I run it manually it runs the Cron successfully
Hi,
I'm using a customized cron task to run php occ files:scan --all
, and since this takes much more time, it doesn't make sense to run it in the same interval as the cron.php file.
Is there a way to have custom intervals for each cron job?
Thank you
Hi @bondif!
I was searching a way to execute the custom script twice a day (#16) and tested a successful way to do it.
It probably can be optimized, however it worked for me, and I'm using it in my Nextcloud home installation.
I have set my NEXTCLOUD_CRON_MINUTE_INTERVAL=5
, in this way I could manage to always have round minutes.
Then I have created the desired script inside the "cron-scripts" folder:
#!/bin/sh
DesiredHourMinute=`date +%H:%M` #Hour and minute are getting stored into this variable
if [[ $DesiredHourMinute == "04:00" ]] || [[ $DesiredHourMinute == "16:00" ]]; then
php occ files:scan --all # Scan all files at the desired hour above
fi
My containers are using UTC, I don't know if there's a way to set them to the local time, but I kept this in mind when I have chosen the time when the scripts should run.
Using this script I achieve the desired full scan twice a day and also it's also registered into the conteiner log:
Container Name: nextcloud-app
Found Nextcloud container with ID 26e0a3ffa81e
Chosen shell "bash" was found in the Nextcloud container
Starting crond
-------------------------------------------------------------
Executing Cron Tasks: Thu Nov 17 22:15:00 UTC 2022
-------------------------------------------------------------
> Nextcloud Container ID: 26e0a3ffa81e
> Running Script: ./run-cron-php.sh
> Running Script: ./Scan-All-Files.sh
Starting scan for user 1 out of 2 (DMTwo)
Starting scan for user 2 out of 2 (User2)
-------------------------------------------------------------
Executing Cron Tasks: Thu Nov 17 22:20:00 UTC 2022
-------------------------------------------------------------
> Nextcloud Container ID: 26e0a3ffa81e
> Running Script: ./run-cron-php.sh
> Running Script: ./Scan-All-Files.sh
> Done
-------------------------------------------------------------
Executing Cron Tasks: Thu Nov 17 22:25:00 UTC 2022
-------------------------------------------------------------
> Nextcloud Container ID: 26e0a3ffa81e
> Running Script: ./run-cron-php.sh
> Running Script: ./Scan-All-Files.sh
> Done
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 9998 | 40685 | 00:10:23 |
+---------+-------+--------------+
> Done
Hi @rcdailey,
Please if possibly add this work around into your instructions.
I think it can help others using custom scripts.
I wish the best to you both.
Thanks a lot!
I am trying to get this running but getting into the error that it can't find the docker container.
docker ps
cb2c6a9f3af2 nextcloud:latest "/entrypoint.sh apac…" 8 days ago Up 8 days 0.0.0.0:8080->80/tcp NextCloud
docker ps --format '{{.Names}},{{.ID}}' | egrep "NextCloud," | awk '{split($0,a,","); print a[2]}'
cb2c6a9f3af2
Result in portainer:
Container Name: NextCloud,
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?,
ERROR: Unable to find the Nextcloud container,
Maybe add debug information on this line when debub is enabled?
Hello,
I'm using Unraid and grabbed your Docker from the Community App Store.
When running, I see the following in my logs:
Executing Cron Tasks: Fri Mar 8 21:15:00 UTC 2024
-------------------------------------------------------------
> Nextcloud Container ID: 1259567c48db
> Running Script: ./run-cron-php.sh
Cannot write into "config" directory!
This can usually be fixed by giving the web server write access to the config directory.
But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.
See https://docs.nextcloud.com/server/28/go.php?to=admin-config
> Done
Any advice? I've tried to add the cron docker to the Nextcloud PHP config as follows:
'trusted_proxies' =>
array (
0 => 'NginxProxyManagerOfficial',
1 => 'Nextcloud-cronjob',
),
This is the error log directly from nextcloud:
I just cant seem to figure it out. Thank you!!
The nextcloud-cronjob container is working great for my docker-compose setup with the following configuration:
nextcloud-cron:
image: rcdailey/nextcloud-cronjob
container_name: nextcloud-cron
restart: unless-stopped
network_mode: none
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/localtime:/etc/localtime:ro
- ${CRONSCRIPTS}:/cron-scripts:ro
environment:
- NEXTCLOUD_CONTAINER_NAME=nextcloud-app
depends_on:
- nextcloud-app
I am now migrating to a swarm service, but it doesn't appear I can use this same cron solution. My understanding is that the swarm naming scheme, due to replicas and unique service names, is not compatible. Example:
As single docker-compose file:
user@docker:$ docker ps --format '{{.Names}},{{.ID}}'
nextcloud-app,84195755d4f2
nextcloud-db,9f027708cd03
nextcloud-redis,7c491729a707
Converted to swarm stack named "nextcloud":
user@docker:$ docker ps --format '{{.Names}},{{.ID}}'
nextcloud_nextcloud-app.1.na20bhtl91z98j8lr5hjjgq69,a61e78034e9d
nextcloud_nextcloud-db.1.tuysjjdnuzetk84y4jmcejeco,86fa6784f9e7
nextcloud_nextcloud-redis.1.yn4h476s5jgp2asjqmb8ezhrp,f12b9876b2c3
Is it possible to get the swarm container names and use them with your cron container? I think your container is the best cron solution for nextcloud. Using official nextcloud:22-apache
base image.
Will search for Nexcloud container as a Docker Compose service
Project: nextcloud, Service: nextcloud-app
ERROR: Unable to find the Nextcloud container
Will search for Nexcloud container as a Docker Compose service
Project: nextcloud, Service: nextcloud-app
ERROR: Unable to find the Nextcloud container
Hey, first of all thanks for that container, but i have a problem that i cant figure out.
I have used a compose file, with the right container name and the basedir (project) name, i also tried setting the project name in an .env file, it is always the same.
i hope this is not bcs you use nextcloud:apache image...
I also tried switching from compose file version 3 to 3.7
The Debug env variable doesn't seem to do sth in this case.
here is the part of the compose:
nextcloud:
depends_on:
- mariadb
- redis
- watchtower
- av
image: nextcloud:19
container_name: nextcloud
links:
- av
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.nextcloud-caldav.redirectregex.permanent=true"
- "traefik.http.middlewares.nextcloud-caldav.redirectregex.regex=^https://(.*)/.well-known/(card|c$
- "traefik.http.middlewares.nextcloud-caldav.redirectregex.replacement=https://$${1}/remote.php/da$
- "traefik.http.middlewares.nextcloud-https.redirectscheme.scheme=https"
- "traefik.http.routers.nextcloud-http.entrypoints=http"
- "traefik.http.routers.nextcloud-http.rule=Host(`cloud.my.domain`)"
- "traefik.http.routers.nextcloud-http.middlewares=nextcloud-https@docker"
- "traefik.http.routers.nextcloud.entrypoints=https"
- "traefik.http.routers.nextcloud.rule=Host(`cloud.my.domain`)"
# Set "Strict-Transport-Security" HTTP header for enhanced security
- "traefik.http.middlewares.sts_headers.headers.stsSeconds=15552000"
- "traefik.http.middlewares.sts_headers.headers.stsIncludeSubdomains=True"
# nextcloud enable middlewares
- "traefik.http.routers.nextcloud.middlewares=nextcloud-caldav@docker,sts_headers"
- "traefik.http.routers.nextcloud.tls=true"
- "traefik.http.routers.nextcloud.tls.certresolver=le"
- "com.centurylinklabs.watchtower.enable=true"
networks:
- default
restart: 'unless-stopped'
volumes:
- ./data/volumes/nextcloud/html:/var/www/html
cron:
image: rcdailey/nextcloud-cronjob
restart: unless-stopped
network_mode: none
container_name: 'cron'
depends_on:
- nextcloud
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/localtime:/etc/localtime:ro
environment:
- NEXTCLOUD_CONTAINER_NAME=nextcloud
- NEXTCLOUD_PROJECT_NAME=traefik
refer to docker/compose#8655 , the rule has changed <project-name>_<service-name>_<replica-number>
to <project-name>-<service-name>-<replica-number>
I tried to change this line
containerName="${NEXTCLOUD_PROJECT_NAME}-"
it seems works fine.
⠿ Container nextcloud-nextapp-1 Running 0.0s
⠿ Container nextcloud-cron-1 Created 0.1s
Attaching to nextcloud-cron-1
nextcloud-cron-1 | Will search for Nexcloud container as a Docker Compose service
nextcloud-cron-1 | Project: nextcloud, Service: nextapp
nextcloud-cron-1 | Found Nextcloud container with ID 396cdc5c652e
nextcloud-cron-1 | Chosen shell "sh" was found in the Nextcloud container
nextcloud-cron-1 | Starting crond
nextcloud-cron-1 | -------------------------------------------------------------
nextcloud-cron-1 | Executing Cron Tasks: Thu Dec 16 17:00:00 HKT 2021
nextcloud-cron-1 | -------------------------------------------------------------
nextcloud-cron-1 | > Nextcloud Container ID: 396cdc5c652e
nextcloud-cron-1 | > Running Script: ./run-cron-php.sh
nextcloud-cron-1 | > Done
tldr: Pay attention to uppercase letters in your project folder name.
I think this is something to either program around or at least document in your (rather nice) documentation.
It seems that docker (or docker compose) removes all case from the folder name (project name). Since my folder had a couple capital letters, and that is how I typed it into the environment variable, your cron service couldn't find it.
Once I understood, it was fairly simple to rename:
NEXTCLOUD_PROJECT_NAME=all_lower_case
While troubleshooting this I initially thought that there was an issue because of the way compose numbers the container names (nextcloud_nextcloud_1) but you seem to have figured out how to work around that.
Thanks,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.