Ejemplo n.º 1
0
 public function init()
 {
     if (!$this->ram_disk->isMounted()) {
         $this->ram_disk->mount();
         Path::mkdir_p_if_not_exists(Path::join($this->mysql_data_path, 'mysql'));
         Path::mkdir_p_if_not_exists($this->tmp_path);
     }
     if ($this->app_armor) {
         $this->app_armor->setTmpPath($this->tmp_path);
         // TODO: move to services.yml or remove entirely
         if (!$this->app_armor->isConfigured()) {
             $this->app_armor->configure();
         }
     }
     $this->buildMySQLDBaseCommand();
     if (!$this->isRunning()) {
         $this->runCommand("echo \"use mysql;\" > {$this->tmp_path}/install_mysql.sql");
         if ($this->getDefaultDataFiles()) {
             $this->runCommand("cat " . implode(' ', array_map('escapeshellarg', $this->getDefaultDataFiles())) . " >> {$this->tmp_path}/install_mysql.sql");
         } else {
             throw new \Exception("Error finding default data files");
         }
         $this->runCommand("{$this->mysqld_base_command} --log-warnings=0 --bootstrap --loose-skip-innodb --max_allowed_packet=8M --default-storage-engine=myisam --net_buffer_length=16K < {$this->tmp_path}/install_mysql.sql");
         $this->runCommand("{$this->mysqld_base_command} > {$this->tmp_path}/mysql-drupal-test.log 2>&1 &");
         $i = 0;
         if (!file_exists($this->mysql_socket_path) or $i > 9) {
             $i++;
             sleep(1);
         }
         if ($i == 9) {
             throw new \Exception("There was a problem starting the MySQLRAM server. We expect to see a socket file at {$this->mysql_socket_path} but it hasn't appeared after 10 waiting seconds.");
         }
         // Probably new DB files
         $i = 0;
         $last_exception = NULL;
         while ($i < 9) {
             $i++;
             try {
                 $this->runCommand("mysqladmin --socket={$this->mysql_socket_path} --user=root --password='' password '{$this->mysql_admin_password}'");
                 break;
             } catch (\Exception $e) {
                 if ($this->adminDatasource->isValid()) {
                     break;
                     // may happen if user killed mysqld without resetting ramdisk
                 }
                 $last_exception = $e;
             }
             sleep(1);
         }
         if ($i == 9) {
             throw $last_exception;
         }
     }
 }
Ejemplo n.º 2
0
 public function init()
 {
     if (!$this->ram_disk->isMounted()) {
         $this->ram_disk->mount();
     }
     Path::mkdir_p_if_not_exists(Path::join($this->mysql_data_path));
     Path::mkdir_p_if_not_exists($this->tmp_path);
     if ($this->app_armor) {
         $this->app_armor->setTmpPath($this->tmp_path);
         // TODO: move to services.yml or remove entirely
         if (!$this->app_armor->isConfigured()) {
             $this->app_armor->configure();
         }
     }
     if (!$this->isRunning()) {
         $this->initializeDatabase();
         $this->runCommand("{$this->getMySQLDBaseCommand()} > {$this->tmp_path}/mysql-drupal-test.log 2>&1 &");
         $i = 0;
         if (!file_exists($this->mysql_socket_path) or $i > 9) {
             $i++;
             sleep(1);
         }
         if ($i == 9) {
             throw new \Exception("There was a problem starting the MySQLRAM server. We expect to see a socket file at {$this->mysql_socket_path} but it hasn't appeared after 10 waiting seconds.");
         }
         // Probably new DB files
         $i = 0;
         $last_exception = NULL;
         while ($i < 9) {
             $i++;
             try {
                 $this->runCommand("mysqladmin --socket={$this->mysql_socket_path} --user=root --password='' password '{$this->mysql_admin_password}'");
                 break;
             } catch (\Exception $e) {
                 if ($this->adminDatasource->isValid()) {
                     break;
                     // may happen if user killed mysqld without resetting ramdisk
                 }
                 $last_exception = $e;
             }
             sleep(1);
         }
         if ($i == 9) {
             throw $last_exception;
         }
     }
 }