-
Notifications
You must be signed in to change notification settings - Fork 495
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
Question: use of cron #280
Comments
The The current solution is to either mount the |
Works for me! Thank you. |
Ok so maybe not so fast 😢 . I mounted the
The file is marked as
However, the job does not seem to be running (no log.txt file being created/updated and no docker stdout either). What am I missing? |
I see a |
OK so, interestingly enough. I changed my image to I am mounting I can see the job running on stdout. Which begs the question, why does the job not run on the |
UPDATE: Went back to mounting |
Any update on why cron.d jobs don't seem to be working on the alpine variant? |
Sorry, won't have time before christmas to look into it |
No worries. Have a merry Christmas! |
Hey man, just touching base with you on this. It would be awesome if cron would work as expected on the alpine tag, as the image is much leaner. |
Same problem here. Jobs created via |
BTW: Starting the image with |
Any news on this? Currently I work around this issue with:
|
@hhoechtl Is the alpine variant no longer being actively developed? I notice that you likely have most of your images on autobuild, as I see pretty recent image updates, even to the alpine one, which is why I was asking. As you can understand, a lot of us consider your images to be of utmost quality and maintenance, but it is important to know if you are intending to continue maintaining them long term. 😃 |
I'm maintaining as many versions as I can, but my focus is clearly on the official PHP7.x images. Just a small hint (I don't have much time atm): the cron service itself must be enabled using Usually we built our own images based on the webdevops images, which have this command
I've personally never looked into or used the |
The alpine image does have the cron service enabled:
|
I'm struggling with this as well. The crond is running, but alpine uses the Busybox crond which probably bahaves different compared to the "real" crond. For starters, it looks for crontabs in If you create file
You would see that it starts outputting
Meaning it is running this cron as user application. It has to be named application (or any other valid user), otherwise it won't execute. |
I don't know much about alpine but It might be a problem with busybox, as we are having a similar issue (cron not executing) on versions or Nextcloud that are build on top of alpine. |
Problem and problem... the thing is that the alpine-image has the same cron.d structure and script as the ubuntu one, but they are running different crond implementations. The busybox crond doesn't load the /etc/cron.d scripts. I'm not sure if it would be possible to run them either. |
@pomazanbohdan Thank you for your explanation. Works like expected, if the permissions are correct on the docker host! I'm putting here my TYPO3ish everyday crontab line, if somebody else needs it. It's the content of my
|
Hello, I've been trying for a long time to get the CronJob running properly. |
FROM webdevops/php-apache:7.4-alpine
COPY etc/ /opt/docker/etc/
Therefore this ENV variable is only for applicatoin parameters for cron itself like described here: https://linux.die.net/man/8/cron |
Hey guys, I want to come back to that. If I mount this under /var/spool/cron/crontabs/ then it will be executed by user root but not by application. So my approach was just to mount this and specify the user in the cron file. But the "column" with the user buw the username is interpreted as a command. I see that under Portainer in the logs that he does not find the command application. I let it go like this now. All crons run as root, but every 15 minutes I run a cron that changes the directory /tmp/ and everything below /app/ with chown -R 1000: 1000. Not nice but it works for now. maybe someone can tell me what I have to do or where to mount that with the cron files of root and application with the correct rights etc. |
Sorry I have to ask again:
The 2 crons look like this.
root
All crons work except for the one with / usr / local / bin / php and I don't see them in the logs
I comment that /bin/bash from is in the logs
If I run it as a user application in the console, everything works |
Alpine versions of "webdevops/php-nginx....-alpine" run BusyBox version of cron, you can check with: You can put tasks in the /etc/periodic folders: 15min or daily or hourly or monthly or weekly OR you can replace the file at /var/spool/cron/crontabs/root which runs and therefore disables the default periodic schedule folders. Dockerfile example: mycrontask example: note that there is no user parameter and I use absolute paths, thats why I left the symfony command in the example |
I've been having a similar issue with struggling to get the cron working. I found the simplest way to set up my own cron schedule was to edit the Add this or similar to your RUN echo "* * * * * cd /app && php artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root Entry Breakdown:
|
I invested a few hours to find out how exactly the execution of user crontabs works in the Alpine and Debian images. I think I understand it now and can provide a script to help you easily install a working user crontab: #!/bin/bash
source /etc/os-release
if [ "$ID" == "alpine" ]; then
CRONTAB_BASE="/etc/crontabs"
if [[ -d "/opt/docker/etc/crontabs/" ]]; then
find /opt/docker/etc/crontabs -type f | while read CRONTAB_FILE; do
CRONTAB_FILENAME="$(basename $CRONTAB_FILE)"
if [[ ! -d "$CRONTAB_BASE" ]]; then
mkdir -p $CRONTAB_BASE
fi
echo "-> Deploy $CRONTAB_FILENAME to $CRONTAB_BASE"
cat $CRONTAB_FILE >> /etc/crontabs/$CRONTAB_FILENAME
chown root:root -- "$CRONTAB_BASE/$CRONTAB_FILENAME"
done
fi
elif [ "$ID" == "debian" ]; then
CRONTAB_BASE="/var/spool/cron/crontabs"
if [[ -d "/opt/docker/etc/crontabs/" ]]; then
find /opt/docker/etc/crontabs -type f | while read CRONTAB_FILE; do
CRONTAB_FILENAME="$(basename $CRONTAB_FILE)"
if [[ ! -d "$CRONTAB_BASE" ]]; then
mkdir -p $CRONTAB_BASE
fi
echo "-> Deploy $CRONTAB_FILENAME to $CRONTAB_BASE"
cat $CRONTAB_FILE >> $CRONTAB_BASE/$CRONTAB_FILENAME
chown $CRONTAB_FILENAME:$CRONTAB_FILENAME -- "$CRONTAB_BASE/$CRONTAB_FILENAME"
chmod 0600 "$CRONTAB_BASE/$CRONTAB_FILENAME"
done
fi
else
echo "Distribution $ID not supported by cron fix script!"
fi Copy this file inside the docker image to During my research, I found that in the Alpine image, cron expects the file to be owned by the root user and group and located in |
I tested it for two days. I think it's a user privilege issue You can run the * * * * * root /bin/echo 1> command. > /tmp/test.log My solution: Tortured for a long time😭 |
Commands in your # Copy crontab file
COPY ./docker/crontabs/application /var/spool/cron/crontabs/application
# Set the correct permission
RUN chmod 0600 /var/spool/cron/crontabs/application Content in the * * * * * cd /var/www/html && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
This setup is tailored for the Laravel scheduler. Adjust the command and path according to your configuration. |
Here is my solution for CRON not working in webdevops/php-apache:5.6 The problem is, that the script The solution is to add an extra line before "done": # Install crontab files
if [[ -d "/opt/docker/etc/cron" ]]; then
mkdir -p /etc/cron.d/
find /opt/docker/etc/cron -type f | while read CRONTAB_FILE; do
# fix permissions
chmod 0644 -- "$CRONTAB_FILE"
# add newline, cron needs this
echo >> "$CRONTAB_FILE"
# Install files
cp -a -- "$CRONTAB_FILE" "/etc/cron.d/$(basename "$CRONTAB_FILE")"
crontab "/etc/cron.d/$(basename "$CRONTAB_FILE")"
done
fi Then mount the fixed script and the cronjobs some-project:
image: webdevops/php-apache:5.6
restart: always
volumes:
- type: bind
source: /somedir/cron
target: /opt/docker/etc/cron
consistency: cached
- type: bind
source: /somedir/10-init-fixed.sh
target: /opt/docker/bin/service.d/cron.d/10-init.sh
consistency: cached would be nice if it would be fixed in future releases. Edit: There should be only one file in /opt/docker/etc/cron. If there are multiple files (including hidden files), only the last file will be used for the crontab. You can check if it's working by executing the command. Your cron jobs should be listed.
|
Hopefully this is a simple question. How does one properly implement cron jobs using the webdevops images? I am specifically using the webdevops/php-apache:alpine image.
I know the ENV var (
SERVICE_CRON_OPTS
) allows for cron options but I do not see how to properly set up the jobs in the documentation.I am currently mounting the
/etc/cron.d
folder to a persisted volume, but I suspect this is not the best way to go about it...Thank you for your help!
The text was updated successfully, but these errors were encountered: