Keep laravel queue:work running while in jailshell

388 Views Asked by At

I'm having issues keeping the queue:work command running on my server. I tried nohup, but as soon as I close the terminal (which times out every 5 minutes or so no matter what I've tried) the process goes away.

I thought about running a script in cron to kick off the nohup command, however that runs in jailshell too so I have no way of seeing if the process is still running from a previous cron or not and I don't want a potential 20k copies of this running because it's trying to kick off every minute.

I also don't have access to install software to install Supervisord.

So, what other solutions can I use to ensure this stays running?

EDIT I contacted the support for my host, and pretty much it looks like there are no real alternatives for me. I think I'm going to have to set this project up on Linode, or rework things to not have queuing tasks.

1

There are 1 best solutions below

0
On

It seems that the problem resides in the shell configuration, because the command ps is rewritten to show only the children process.

The solution is to ask your hosting provider (or change it yourself if allowed) to set this variable:

SHELL="/bin/bash"

This simple fix allowed me to have the function working properly.

Now my Kernel.php looks as follows:

$command = "ps faux | grep queue:work";

exec($command, $task_list);
// Process are duplicate in ps and show also the command as two single lines
$running_process = (count($task_list) / 2) - 1;

if($running_process < 1)
    $schedule->command('queue:work --queue=high,low --tries=3')
        ->everyMinute();
else if($running_process > 5)
    // If too many are active, restart everything to avoid overload
    $schedule->call(function(){
        Artisan::call('queue:restart');
    })->everyMinute();

This code makes sure that at least one worker is always running, and at the same time forces a restart if you have more that 5 workers active.