Domanda

My Linux distro does not have a system cron by default. I can install one, but as an alternative, is it possible to replace that functionality for Magento 2.3 with a systemd timer? If so, what are the steps?

È stato utile?

Soluzione

You definitely can replace the cron job with a timer. The main disadvantages to using one would be, that setup is a bit more complex and it not being a standard implementation.

Note: I haven't tested the following and don't have a ton of experience with timers, but should atleast point you in the right direction.

Creating a Systemd Timer

Create a file at /home/client/crons/prod.sh

/usr/bin/php /var/www/mage/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/mage/var/log/magento.cron.log &
/usr/bin/php /var/www/mage/update/cron.php >> /var/www/mage/var/log/update.cron.log &
/usr/bin/php /var/www/mage/bin/magento setup:cron:run >> /var/www/mage/var/log/setup.cron.log &

Create a file at the following path /etc/systemd/system/client_magento_prod.service

[Unit]
Description=Clients Magento 2 Prod Cron Service

[Service]
Type=oneshot
ExecStart=/usr/bin/sh /home/client/crons/prod.sh
User=magefilesystemuser
Group=magefilesystemgroup

Create a file at the following path /etc/systemd/system/client_magento_prod.timer

[Unit]
Description=Clients Magento 2 Prod Cron Timer

[Timer]
OnCalendar=*:0/5:0

[Install]
WantedBy=timers.target

Enable the timers with the following commands

systemctl daemon-reload
systemctl enable client_magento_prod.timer
systemctl start client_magento_prod.timer

And to check what timers are active / timings

systemctl list-timers
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top