Ejemplo n.º 1
0
 /**
  * Manages php fpm via augeas and monit
  *
  * @param $meta
  * @throws \Exception
  */
 protected function manageFpm($meta)
 {
     if (empty($meta['fpm']['port']) && empty($meta['_old']['fpm']['port'])) {
         return;
     }
     if ($meta['installed'] && !empty($meta['fpm']['port'])) {
         $this->output->writeInfo("Checking fpm");
     } else {
         $this->output->writeInfo("Removing fpm");
     }
     $fs = Util::getFilesystem();
     $monit_conf_file = "/etc/monit/conf.d/php-{$meta['_build']}-fpm.conf";
     $apache_conf_file = "/etc/apache2/php/php-{$meta['_build']}-fpm.conf";
     if ($meta['installed'] && empty($meta['fpm']['port']) && !empty($meta['_old']['fpm']['port'])) {
         $this->stopFpm($meta['_build']);
     }
     if (!$meta['installed'] || empty($meta['fpm']['port'])) {
         if (file_exists($monit_conf_file)) {
             $this->output->writeInfo("Removing monit php-fpm config file '{$monit_conf_file}'");
             $fs->remove($monit_conf_file);
         }
         if (file_exists($apache_conf_file)) {
             $this->output->writeInfo("Removing apache php-fpm config file '{$apache_conf_file}'");
             $fs->remove($apache_conf_file);
         }
         return;
     }
     $fpm_config_file = $meta['_path'] . '/etc/php-fpm.conf';
     $fpm_config_updated_1 = Util::augeas('PHP', $fpm_config_file, 'www/listen', '127.0.0.1:' . $meta['fpm']['port']);
     $fpm_config_updated_2 = Util::augeas('PHP', $fpm_config_file, 'www/user', 'www-data');
     $fpm_config_updated_3 = Util::augeas('PHP', $fpm_config_file, 'www/group', 'www-data');
     if (0 === $fpm_config_updated_1 || 0 === $fpm_config_updated_2 || 0 === $fpm_config_updated_3) {
         $this->output->writeError("Failed to configure fpm config file '{$fpm_config_file}'");
     } else {
         if (2 === $fpm_config_updated_1 || 2 === $fpm_config_updated_2 || 2 === $fpm_config_updated_3) {
             $this->output->writeInfo("Configured fpm");
         }
     }
     $monit_conf_template = Util::renderTemplate('monit/conf.d/php-fpm.conf.php', ['build' => $meta['_build'], 'port' => $meta['fpm']['port']]);
     if (!file_exists($monit_conf_file) || md5($monit_conf_template) !== md5_file($monit_conf_file)) {
         $this->output->writeInfo("Writing monit php-fpm config file '{$monit_conf_file}'");
         $fs->write($monit_conf_file, $monit_conf_template, 'root');
     }
     $apache_conf_template = Util::renderTemplate('apache/php/php-fpm.conf.php', ['build' => $meta['_build'], 'port' => $meta['fpm']['port']]);
     if (!file_exists($apache_conf_file) || md5($apache_conf_template) !== md5_file($apache_conf_file)) {
         $this->output->writeInfo("Writing apache php-fpm config file '{$apache_conf_file}'");
         $fs->write($apache_conf_file, $apache_conf_template, 'root');
     }
     if (!isset($meta['fpm']['autostart']) || $meta['fpm']['autostart']) {
         ServiceManager::addService("php-{$meta['_build']}-fpm");
     }
 }