I have a Laravel 10 project, and I want to use a supervisor to deal with processes like queuing and scheduling. I have already done a supervisor configuration for the queue:work command.
#/etc/supervisor/conf.d/laravel-worker.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/laravel-worker.sh
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/laravel-worker.log
environment=SITE_WEB_VERSION=20240328-163200
#/usr/local/bin/laravel-worker.sh
#!/bin/bash
SITE_WEB_DIR="/home/user/laravel/releases"
SITE_WEB_VERSION="20240328-163200"
ARTISAN_PATH="$SITE_WEB_DIR/$SITE_WEB_VERSION/artisan"
if [ -f "$ARTISAN_PATH" ]; then
php "$ARTISAN_PATH" queue:work --sleep=3 --tries=3
else
echo "$SITE_WEB_VERSION doesn't exist."
fi
This one works fine:
# sudo supervisorctl status
laravel-worker:laravel-worker_00 RUNNING pid 38023, uptime 0:14:41
So, I want to do the same with the Laravel scheduler.
#/etc/supervisor/conf.d/laravel-scheduler.conf
[program:laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/laravel-scheduler.sh
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/laravel-scheduler.log
environment=SITE_WEB_VERSION=20240328-163200
#/usr/local/bin/laravel-scheduler.sh
#!/bin/bash
SITE_WEB_DIR="/home/user/laravel/releases"
SITE_WEB_VERSION="20240328-163200"
ARTISAN_PATH="$SITE_WEB_DIR/$SITE_WEB_VERSION/artisan"
if [ -f "$ARTISAN_PATH" ]; then
php "$ARTISAN_PATH" schedule:run >> /dev/null 2>&1
else
echo " $SITE_WEB_VERSION doesn't exist."
fi
But this process doesn't work properly, it rendes an error when I ran sudo supervisorctl start laravel-scheduler:*: laravel-scheduler:laravel-scheduler_00: ERROR (spawn error)
laravel-scheduler:laravel-scheduler_00 FATAL Exited too quickly (process log may have details)
No errors on /var/log/laravel-scheduler.log
And I have these logs on /var/log/supervisor/supervisor.log
2024-03-29 11:33:22,580 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message.
2024-03-29 11:33:22,581 INFO Included extra file "/etc/supervisor/conf.d/laravel-scheduler.conf" during parsing
2024-03-29 11:33:22,581 INFO Included extra file "/etc/supervisor/conf.d/laravel-worker.conf" during parsing
2024-03-29 11:33:22,583 INFO RPC interface 'supervisor' initialized
2024-03-29 11:33:22,583 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2024-03-29 11:33:22,584 INFO supervisord started with pid 38335
2024-03-29 11:33:23,588 INFO spawned: 'laravel-scheduler_00' with pid 38337
2024-03-29 11:33:23,592 INFO spawned: 'laravel-worker_00' with pid 38338
2024-03-29 11:33:23,805 INFO exited: laravel-scheduler_00 (exit status 0; not expected)
2024-03-29 11:33:24,809 INFO spawned: 'laravel-scheduler_00' with pid 38347
2024-03-29 11:33:24,811 INFO success: laravel-worker_00 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-03-29 11:33:25,032 INFO exited: laravel-scheduler_00 (exit status 0; not expected)
2024-03-29 11:33:27,313 INFO spawned: 'laravel-scheduler_00' with pid 38354
2024-03-29 11:33:27,531 INFO exited: laravel-scheduler_00 (exit status 0; not expected)
2024-03-29 11:33:30,538 INFO spawned: 'laravel-scheduler_00' with pid 38358
2024-03-29 11:33:30,769 INFO exited: laravel-scheduler_00 (exit status 0; not expected)
2024-03-29 11:33:31,770 INFO gave up: laravel-scheduler_00 entered FATAL state, too many start retries too quickly
I tried some things :
I can run manually laravel-scheduler.sh and I have no errors so it seems that it's not due to this file.
I restarted many times supervisor with
sudo service supervisor restartI also verified permissions on worker and scheduler and they're the same :
-rw-r--r-- 1 root root 289 mars 29 11:32 /etc/supervisor/conf.d/laravel-scheduler.conf
-rw-r--r-- 1 root root 280 mars 29 10:33 /etc/supervisor/conf.d/laravel-worker.conf
-rwxr-xr-x 1 root root 680 mars 29 11:33 /usr/local/bin/laravel-scheduler.sh
-rwxr-xr-x 1 root root 740 mars 29 09:26 /usr/local/bin/laravel-worker.sh
- I try to run ``` php artisan schedule:run ``` manually and it works, it renders : ``` INFO No scheduled commands are ready to run.```
For information there is my app/Console/Kernel.php file :
```php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
$schedule->command('megaphone:clear-announcements')->daily();
}
/**
* Register the commands for the application.
*/
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
- I try to run the only command on scheduler manually :
php artisan megaphone:clear-announcementsand it renders no errors.
Now, I need to figure out where to look. Does anyone have an idea of where the problem could be?