docker icon indicating copy to clipboard operation
docker copied to clipboard

Allow custom cron jobs

Open gjedeer opened this issue 3 years ago • 2 comments

I'm looking for a way to make occ preview:generate-all run periodically in a Docker setup.

Maybe adding a line like this to /var/spool/cron/crontabs/www-data would be a good way to enable using custom cron jobs?

*/5 * * * * if [ -f /var/www/html/cron_custom.sh ]; then bash /var/www/html/cron_custom.sh; fi

gjedeer avatar Jun 22 '22 11:06 gjedeer

I was looking to execute a periodic job for this exact purpose too. I was hoping for something in the README to teach us how to use the supervisord they embed in the cron Dockerfile example, but I don't understand how to use it.

The next closest thing would be to add in the host a cron job running something like docker exec --user www-data CONTAINER_ID php occ preview:generate-all

josejsarmento avatar Jul 26 '22 11:07 josejsarmento

I had no idea there's supervisord in there. It can be turned into a poor man's cron with a trick but it's very inflexible when used this way. It can be ran every minute or every hour.

But I think using cron for cron jobs would be better.

gjedeer avatar Jul 26 '22 15:07 gjedeer

I was facing the same issue. For now, I'm using this workaround to run occ preview:generate-all every 15 mins:

The user is member of the docker group: sudo usermod -a -G docker USERNAME

  • User crontag, crontab -e:

    */15 * * * * $HOME/pre-gen.sh > /dev/null 2>&1
    
  • $HOME/pre-gen.sh

    #!/usr/bin/env bash
    
    echo "--- $(date --utc +%FT%TZ) ----------------------------------------" >>$HOME/pre-generate.log 2>&1
    docker exec -i --user 33 nextcloud-app-1 ./occ preview:pre-generate -v >>$HOME/pre-generate.log 2>&1
    

BWibo avatar Oct 09 '22 19:10 BWibo

I'm doing the same but it's a hack.

gjedeer avatar Oct 11 '22 07:10 gjedeer

https://github.com/nextcloud/docker/issues/361

jjasoncool avatar Jan 17 '23 01:01 jjasoncool

@jjasoncool yeah, building your own Dockerfile or running cronjobs on the host, not really solutions to the problem.

gjedeer avatar Jan 17 '23 07:01 gjedeer

You can ref this, build this is running normally. https://github.com/nextcloud/docker/issues/1695#issuecomment-1383615123

jjasoncool avatar Jan 18 '23 14:01 jjasoncool

Duplicate of #820

J0WI avatar Apr 04 '23 18:04 J0WI