Orzu Ionut
2 years ago
2 changed files with 21 additions and 81 deletions
@ -1,79 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Console\Commands; |
|
||||
|
|
||||
use Exception; |
|
||||
use Illuminate\Console\Command; |
|
||||
use Illuminate\Support\Facades\Storage; |
|
||||
|
|
||||
class DeployWorker extends Command |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* The name and signature of the console command. |
|
||||
* |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $signature = 'queue:deploy-supervisor'; |
|
||||
|
|
||||
/** |
|
||||
* The console command description. |
|
||||
* |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $description = 'Adds the supervisorctl config file for laravel queues. Must be ran as root!'; |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* Create a new command instance. |
|
||||
* |
|
||||
* @return void |
|
||||
*/ |
|
||||
public function __construct() |
|
||||
{ |
|
||||
parent::__construct(); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* Execute the console command. |
|
||||
* |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function handle() |
|
||||
{ |
|
||||
$workerName = 'queue-worker-'.str_replace(' ', '-', strtolower(env('APP_NAME'))).'-'.str_replace(' ', '-', strtolower(env('APP_ENV'))); |
|
||||
$workerFile = $workerName.'.conf'; |
|
||||
|
|
||||
try { |
|
||||
Storage::disk('supervisor')->put($workerFile, '[program:'.$workerName.'] |
|
||||
process_name=%(program_name)s_%(process_num)02d'); |
|
||||
Storage::disk('supervisor')->append($workerFile, 'command=php '.base_path().'/artisan queue:listen --queue=sd_ingest,default --tries=2 --timeout=180'); |
|
||||
Storage::disk('supervisor')->append($workerFile, 'autostart=true |
|
||||
autorestart=true |
|
||||
user=www-data |
|
||||
numprocs=3 |
|
||||
redirect_stderr=true |
|
||||
stdout_logfile=/var/log/queue/'.$workerName.'.log'); |
|
||||
} catch (Exception $e) { |
|
||||
$this->info('supervisor script failed to install. Did you install supervisor and are you running this script as root?'); |
|
||||
|
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
$this->info('supervisor script installed'); |
|
||||
|
|
||||
try { |
|
||||
exec('sudo supervisorctl reread'); |
|
||||
exec('sudo supervisorctl update'); |
|
||||
exec('sudo supervisorctl stop '.$workerName.':*');//in case it's already started
|
|
||||
exec('sudo supervisorctl start '.$workerName.':*'); |
|
||||
} catch (Exception $e) { |
|
||||
$this->info('failed to start queue worker'); |
|
||||
|
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
$this->info('queue worker started'); |
|
||||
} |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue