Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Exception;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Storage;
  6. class DeployWorker extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'queue:deploy-supervisor';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Adds the supervisorctl config file for laravel queues. Must be ran as root!';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $workerName = 'queue-worker-'.str_replace(' ', '-', strtolower(env('APP_NAME'))).'-'.str_replace(' ', '-', strtolower(env('APP_ENV')));
  37. $workerFile = $workerName.'.conf';
  38. try {
  39. Storage::disk('supervisor')->put($workerFile, '[program:'.$workerName.']
  40. process_name=%(program_name)s_%(process_num)02d');
  41. Storage::disk('supervisor')->append($workerFile, 'command=php '.base_path().'/artisan queue:listen --queue=sd_ingest,default --tries=2 --timeout=180');
  42. Storage::disk('supervisor')->append($workerFile, 'autostart=true
  43. autorestart=true
  44. user=www-data
  45. numprocs=3
  46. redirect_stderr=true
  47. stdout_logfile=/var/log/queue/'.$workerName.'.log');
  48. } catch (Exception $e) {
  49. $this->info('supervisor script failed to install. Did you install supervisor and are you running this script as root?');
  50. return;
  51. }
  52. $this->info('supervisor script installed');
  53. try {
  54. exec('sudo supervisorctl reread');
  55. exec('sudo supervisorctl update');
  56. exec('sudo supervisorctl stop '.$workerName.':*');//in case it's already started
  57. exec('sudo supervisorctl start '.$workerName.':*');
  58. } catch (Exception $e) {
  59. $this->info('failed to start queue worker');
  60. return;
  61. }
  62. $this->info('queue worker started');
  63. }
  64. }