Как в Kubuntu 18 запустить шедулер на laravel приложение

mstdmstd

Новичок
Всем привет
Хочу на своей Kubuntu 18 запустить шедулер на laravel 5.7 приложение
Сделал и проверил методы в своем приложении
И в файл /etc/crontab
добавил одну строку и получилось :
Код:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
2 * * * * root  /mnt/_work_sdb8/wwwroot/lar/Votes/artisan schedule:run >> /dev/null 2>&1

И выполнил :
Код:
systemctl restart cron
root@serge:/mnt/_work_sdb8/wwwroot/lar/Votes# systemctl status cron
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-10-11 14:57:15 EEST; 11s ago
Docs: man:cron(8)
Main PID: 11625 (cron)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/cron.service
└─11625 /usr/sbin/cron -f

11 14:57:15 serge systemd[1]: Started Regular background program processing daemon.
11 14:57:15 serge cron[11625]: (CRON) INFO (pidfile fd = 3)
11 14:57:15 serge cron[11625]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Я полагал, что каждые 2 минуты будет выполняться мой
шедулер(там удаляются строки из одной из таблиц и имитируется отправка емейлов сбросом файлов с содержимым на диск) - но похоже ничего не выполняется.
Там есть какие-то логи ?
Я искал в /var/log файлы по подстроке “*cron*” но ничего не нашел...

Спасибо!
 

fixxxer

К.О.
Партнер клуба
Во-первых, не надо запускать рутом, надо запускать от того пользователя, от которого обычно работает laravel.

Во-вторых, laravel сам пишет логи в соответствии со своими настройками, если, конечно, до него вообще дело дошло.

В-третьих, раз ты написал ">> /dev/null 2>&1", ты сам не хочешь видеть отчетов крона:

When executing commands, any output is mailed to the owner of the crontab or to the user named in the MAILTO environment variable in the crontab, if such exists.
В-четвертых, "я полагал, что каждые 2 минуты" - неправльно, то, что написано - это каждый час, когда будет 2 минуты. man 5 crontab.

В-пятых, раз у тебя systemd, искать в /var/log не надо, man journalctl.
 

mstdmstd

Новичок
Спасибо, много полезного !

Запустил вручную :
Код:
 $ /mnt/_work_sdb8/wwwroot/lar/Votes/artisan schedule:run
No scheduled commands are ready to run.
И непонятно почему нет комманд при запуске:

В app/Console/Kernel.php:

Код:
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [

'\App\Console\Commands\checkNewContactUs',
'\App\Console\Commands\checkNewUsers',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('checkNewContactUs:check_new_contact_us')->hourlyAt(21);
$schedule->command('checkNewUsers:check_new_user')->hourlyAt(23);
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}

Определение одной из комманд в app/Console/Commands/checkNewContactUs.php:
Код:
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\library\AppCronTasks;

class checkNewContactUs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'checkNewContactUs:check_new_contact_us';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Check if there are new contact_us and send summary report to admins of the site ';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$appCronTasks = new AppCronTasks();
$appCronTasks->notifyNewContactUs(true);
}
}

Мои команды в списке команд :
Код:
# php artisan list
...
checkNewContactUs
checkNewContactUs:check_new_contact_us Check if there are new contact_us and send summary report to admins of the site
checkNewUsers
checkNewUsers:check_new_user Check if there are new users and send summary report to admins of the site

В routes/console.php я ничего не добавлял :
Код:
<?php

use Illuminate\Foundation\Inspiring;

Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->describe('Display an inspiring quote');

Что я упустил?

И в кроне я использовал имя пользователя в системе
Код:
54 * * * * serge /mnt/_work_sdb8/wwwroot/lar/Votes/artisan schedule:run > dev
по крайней мере
Код:
systemctl status cron
на это имя не ругается...
 

AnrDaemon

Продвинутый новичок
Ещё раз, не надо лезть в системный кронтаб!
Запустите `crontab -e` от нужного пользователя.
 

fixxxer

К.О.
Партнер клуба
С именем пользователя в /etc/crontab нормально, один фиг.

Другой вопрос, принадлежит ли /mnt/_work_sdb8/wwwroot/lar этому пользователю.

@mstdmstd, сделай в ларавеле запуск какой-нибудь тестовой фигни каждую минуту и проверяй на этом.
 

fixxxer

К.О.
Партнер клуба
Что у тебя не вяжется?

В /etc/crontab на одно поле больше, чем в per-user crontab-е, там перед командой указывается имя пользователя.
 
Сверху