OpenSource CLI-App to install and handle stuff related to Web-Server
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.

85 lines
2.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use App\Facades\Install;
  6. use App\BladeFile;
  7. /**
  8. * Nginx install
  9. *
  10. *
  11. */
  12. class NginxInstallCommand extends Command
  13. {
  14. /**
  15. * The signature of the command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'nginx:install {--user=www-data} {--environment=production}';
  20. /**
  21. * The description of the command.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'Install Nginx';
  26. /**
  27. * Execute the console command.
  28. *
  29. * @return mixed
  30. */
  31. public function handle()
  32. {
  33. $this->info('Nginx installing...');
  34. exec('apt update 2>&1', $output);
  35. exec('apt install -y nginx 2>&1', $output);
  36. // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
  37. $this->line(implode("\n", Install::filterAptMessages($output)));
  38. // check if nginx is ready and installed
  39. if (Install::isReady('nginx')) {
  40. $this->info('Nginx create configuration...');
  41. // copy snippets
  42. exec('cp '.base_path().'/resources/nginx/snippets/*.conf /etc/nginx/snippets');
  43. $configuration = [
  44. 'user' => $this->option('user'),
  45. 'environment' => $this->option('environment')
  46. ];
  47. // get workers
  48. $output = [];
  49. exec('echo $(grep ^processor /proc/cpuinfo | wc -l)', $output);
  50. $configuration['processes'] = $output[0];
  51. // get connections
  52. exec('echo $(ulimit -n)', $output);
  53. $configuration['connections'] = $output[1];
  54. $bladeFile = new BladeFile('/resources/nginx');
  55. $bladeFile->put('nginx', '/etc/nginx/nginx.conf', $configuration);
  56. // adding ufw to nginx
  57. $output = [];
  58. $this->info('Nginx adding ufw rules...');
  59. exec('ufw allow "Nginx Full" 2>&1', $output);
  60. $this->line(implode("\n", $output));
  61. $this->info('Nginx installing...Success! \o/');
  62. } else {
  63. $this->error('Failed! Please check log-file!');
  64. }
  65. }
  66. }