Laravel artisan cron task not working on ubuntu 18.10 - laravel

Hello I have enabling the cron feature for Laravel on Ubuntu 18.10 on Vultr VPS server.
I have added the cron task to the cron jobs list using the command
crontab -e
Then I have added the command listed in the laravel documentation
* * * * * cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1
I have made sure that cron is running and I can see that the task is running if I run
sudo grep -i cron /var/log/syslog|tail -3
Which returns
May 20 20:56:01 HiRe-Pro-Web CRON[1819]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
May 20 20:57:01 HiRe-Pro-Web CRON[1862]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
May 20 20:58:01 HiRe-Pro-Web CRON[1898]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
Does anyone have any suggestions where I'm going wrong here.

Related

Make crontab inside Dockerfile not working

I create a crontab file like this
* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
and a Dockerfile like this
COPY crontab /etc/cron.d/cron
RUN chmod 0644 /etc/cron.d/cron
RUN crontab /etc/cron.d/cron
RUN touch /var/log/cron.log
CMD ["cron", "-f"]
I checked inside container by command service cron status
[ ok ] cron is running.
and crontab -l
* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
All of that look like ok but when I tail -f /var/log/cron.log nothing to happen, how to fix that thank

why laravel task schedular running commands twice after upgrade to laravel 9?

Since we have upgraded our laravel project from laravel 8 to laravel 9. we are facing issue that all the commands and jobs mentioned in kernel.php are running twice because of which the system is creating duplicate entries in DB. we didn't make any changes to the code.
We also upgraded the ubuntu version from 16 to 20.
I checked the cron file by this command crontab -e but there is a written command only once. maybe on the server from somewhere else ubuntu running one more command as well.
Kernel.php
protected function schedule(Schedule $schedule)
{
//POD STATS update job
$schedule->job(new PodStatsJob)->everyTenMinutes();
//Consignment table backup job
#Pickup Email Reminder
$pickup_reminder_time = substr(getSingleOrganisationSetting("pickup_reminder_time"), 0, 5) ?? '07:00';
// $schedule->command('conveyor:indexing')->dailyAt($conveyor_consignment_indexing);
}
when I check with this command ps aux | grep "artisan schedule:run"
I get this
root 1331614 0.0 0.0 2616 528 ? Ss 15:00 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
root 1331616 0.0 0.9 216924 77220 ? S 15:00 0:03 php artisan schedule:run
root 1345894 0.0 0.0 2616 592 ? Ss 17:39 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
ubuntu 1345895 0.0 0.0 2616 600 ? Ss 17:39 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
root 1345896 27.0 0.9 216924 79020 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345897 28.0 0.9 216924 78944 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345911 0.0 0.0 8484 2428 pts/0 S+ 17:39 0:00 grep --color=auto artisan schedule:run
It seems that two users root and ubuntu are running the same command php artisan schedule:run:
root 1345896 27.0 0.9 216924 79020 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345897 28.0 0.9 216924 78944 ? S 17:39 0:00 php artisan schedule:run
You maybe need to run the service on only one user.

crontab does not really start schedule

IN a laravel I have a SnapShot method to copy data to a statistics model.
When I run
/var/www/laravel/artisan schedule:run
data are added to the Statistics-table.
Now I have added the following line to /etc/crontab
* * * * * php /var/www/laravel/artisan schedule:run >> dev/null 2>&1
In my /var/log/syslog I read:
Jul 16 08:53:01 cluego CRON[24524]: (root) CMD (cd /usr/bin/php7.4 && php artisan schedule:run /dev/null 2>&1)
Jul 16 08:53:01 cluego CRON[24523]: (CRON) info (No MTA installed, discarding output)
Jul 16 08:54:01 cluego CRON[24599]: (root) CMD (php /var/www/laravel/artisan schedule:run /dev/null 2>&1)
Jul 16 08:54:01 cluego CRON[24598]: (CRON) info (No MTA installed, discarding output)
The laravel.log shows:
[2021-07-16 09:25:01] production.ERROR: No arguments expected for "schedule:run" command, got "/dev/null". {"exception":"[object] (Symfony\\Component\\Console\\Exception\\$
[stacktrace]
when I run manually I get the following result:
root#xxxx:/var/www/laravel# php artisan schedule:run
Running scheduled command: '/usr/bin/php7.4' 'artisan' statistics:snap > '/dev/null' 2>&1
and a data point is added to Statistics-table, just as it is supposed to.
Can anyone see why the cronjob is not running the statistics:snap command, just like the manual schedule:run does?
The problem is that your coron job is wrongly formatted. From the documentation it should look like this:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
So in your case it should look like:
* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1
I guess you could also try running your version but with the full path to php instead of only php or using /dev/null instead of dev/null
* * * * * php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1
* * * * * /path/to/php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1

Shell scripts stops writing in log file

I am working on a provisioner shell script which after certain tasks writes in a log file. The problem is that after the third write operation it stops and doesn't log anything else, however the script runs successfully with the rest of the operations.
I am using this most simple command:
#!/bin/bash
set -o nounset
set -o errexit
# Set variables
APACHE_USER="www-data"
STORES_PATH="/var/www/x/stores"
LOG_FILE="deploy_store.log"
NEW_DB_PWD="$(openssl rand -base64 12)"
arg1="${1:-}"
echo "'$arg1' provision started on $(date +'%Y-%m-%d %H:%M')" >> "${LOG_FILE}"
git clone git#bitbucket.org:x/y.git ${STORES_PATH}"/$arg1"
echo "Done cloning the repository." >> "${LOG_FILE}"
# Link the store vendor folder
ln -s /srv/x/vendor_5.7 ${STORES_PATH}"/$arg1/vendor"
echo "Done linking the vendor folder." >> "${LOG_FILE}"
# Run the setup composer commands
cd ${STORES_PATH}"/$arg1" && composer dump-autoload
cd ${STORES_PATH}"/$arg1" && php artisan package:discover --ansi
cd ${STORES_PATH}"/$arg1" && php -r "file_exists('.env') || copy('.env.example', '.env');"
cd ${STORES_PATH}"/$arg1" && php artisan key:generate
echo "Done composer setup." >> "${LOG_FILE}" # THIS IS NOT LOGGED.

How to have multiple crontab entries for different projects Laravel task scheduling?

I am using Laravel and am working with scheduling tasks. It is working fine in one project, but I want to use it in another as well. How would I add the crontab entry needed? Here is what my crontab file looks like for my first project:
* * * * * cd ~/code/project1; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
Here is how I've tried to add the second project:
* * * * * cd ~/code/project1; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
* * * * * cd ~/code/project2; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
and
* * * * * cd ~/code/project1; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1,
* * * * * cd ~/code/project2; /usr/local/bin/php && php artisan schedule:run >> /dev/null 2>&1
But neither of these have worked. How would I successfully edit my crontab file for running this command on multiple projects?

Resources