Describe the bug
Reminder and "Keep in Touch" emails are not sent out.
Which version are you using:
I am running MonicaHQ version 2.16.0 on Docker in Google Cloud.
Additional context
The instance is configured to use Mailgun and is able to send password recovery emails without issue.
# Mail credentials used to send emails from the application.
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT="587"
[email protected]
#MAIL_PASSWORD=See .env-monicahq-secretes
MAIL_ENCRYPTION=tls
# Outgoing emails will be sent with these identity
[email protected]
MAIL_FROM_NAME="Monica (cashweaver.com)"
MAILGUN_DOMAIN=mg.cashweaver.com
#MAILGUN_SECRET=See .env-monicahq-secretes
The cron rule is in place and appears to run without error.
$ docker exec -i $(docker-compose ps -q monicahq) ls /etc/periodic/hourly/
monica
$ docker exec -i $(docker-compose ps -q monicahq) cat /etc/periodic/hourly/monica
#!/bin/sh
/usr/bin/php /var/www/monica/artisan schedule:run -v > /proc/1/fd/1 2> /proc/1/fd/2
$ docker exec -i $(docker-compose ps -q monicahq) php artisan schedule:run
Running scheduled command: '/usr/bin/php7' 'artisan' send:reminders > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' send:stay_in_touch > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' monica:calculatestatistics > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' monica:ping > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' monica:clean > '/dev/null' 2>&1
Same issue for me on
Ubuntu 18.04
PHP 7.3
monica v2.16.0
This issue is still happening for me with MonicaHQ 2.17.0 on Docker.
I've updated to version 2.17.0 on Docker. In the process of bringing the image back online I noticed a line in the startup logs: "cron is not launched by default. Add CRON_LEGACY=true, use another container, or use supervisor."
I added CRON_LEGACY=true to my environment configuration and restarted the server. The message went away, which (based on the code) makes me think that cron is running.
I won't know if this fixed anything until tomorrow when my newest reminder is set. I'll update the thread then.
I added
CROM_LEGACY=trueto my environment configuration and restarted the server. The message went away, which (based on the code) makes me think that cron is running.
It didn't worked for me.
I was seeing the same message on logs - thanks to your comment - so I added CRON_LEGACY=true and the message did go away. Inside the container, I can see the process crond -b -l 0 process running.
Then I created some reminders for today and tomorrow and run php artisan schedule:run to force the routine, but the emails are not sent.
So I created another reminder and waited for the scheduled routine to run on its own. Same behavior.
I had the same issue, but php artisan schedule:run was complaining:
In Compiler.php line 36:
Please provide a valid cache path.
After some googling around, I tried running the following commands after backing up my storage directory: php artisan cache:clear && php artisan config:clear && php artisan view:clear.
After that, at least the errors went away:
# php artisan schedule:run
Running scheduled command: '/usr/bin/php7' 'artisan' send:reminders > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' send:stay_in_touch > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' monica:calculatestatistics > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' monica:ping > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' monica:clean > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7' 'artisan' monica:updategravatars > '/dev/null' 2>&1
I will try to remember to report back if this helps.
I have found the issue. Note that I am using CRON_LEGACY=true.
The cronjob in /etc/periodic/hourly/monica tries to call /usr/src/monica/artisan, but that will fail because that directory does not have the storage and cache mounted.
entrypoint.sh copies /usr/src/monica to /var/www/monica, where the storage directory is. Making the cronjob call /var/www/monica/artisan instead of /usr/src/monica/artisan makes the notifications work again.
As a workaround, I created a script fix-crontab-and-exec.sh:
#!/bin/sh
set -eu
echo "Patching /etc/periodic/hourly/monica for https://github.com/monicahq/monica/issues/3668"
sed -i "s@/usr/src/monica/artisan@/var/www/monica/artisan@g" /etc/periodic/hourly/monica
exec entrypoint.sh "$@"
I then mount and use this script using the following lines in my compose file:
command: ["fix-crontab-and-exec.sh", "apache2-foreground"]
volumes:
- ./fix-crontab-and-exec.sh:/usr/local/bin/fix-crontab-and-exec.sh:ro
Now my notifications work again. I hope this workaround helps others and gives enough insight to fix the issue in the official docker image.
@RagingCactus Thank you for the solution! I don't use cron legacy anymore.
You might want to use supervisord, or another docker instance for run cron script.
See https://github.com/monicahq/monica/tree/master/scripts/docker/.examples for some examples.
BTW I didn't saw the problem, because I only use fpm variant ;)
@asbiin Thanks for the fix. From looking at the code, however, I don't think another container instance running cron.sh will work just yet.
When running the default command apache2-foreground the entrypoint.sh copies /usr/src/monica to /var/www/monica, where the storage directory is. However, it only does that when the command is starting with apache or is php-fpm7.
https://github.com/monicahq/monica/blob/751d4f5e5565ba9a4213dbf3724a1b5218831ee3/scripts/docker/entrypoint.sh#L32
When the command cron.sh is passed to the entrypoint script, it will run cron without copying the files over to the directory the cronjob is trying to run in after 2662a5f5f3bf10ea7aa218a986a4d5a6e22191b2.
Note that I haven't tried the new version yet, but from reading the code this seems to be the case. Please correct me if I'm wrong here.
Thanks again for your great work!
@RagingCactus Yes indeed, the examples are not fine.
I have this on my docker-compose:
cron:
image: monicahq/monicahq:fpm
env_file: .env
restart: always
volumes:
- data:/var/www/monica/storage
- www:/var/www/monica:ro
command: cron.sh
depends_on:
- db
- redis
I'll fix the examples
I have updated my docker configuration to include the cron and queue containers as per your example, and created fresh containers and volumes (and hit a different error in the process. I have set up a reminder for tomorrow and we'll see how things go.
Success! The emails came through with the docker setup I included in my previous comment. Thank you all for the effort you put in!
Most helpful comment
The cron rule is in place and appears to run without error.