diff --git a/base/DatabaseInstaller.php b/base/DatabaseInstaller.php index 3cb21b0..72deacc 100644 --- a/base/DatabaseInstaller.php +++ b/base/DatabaseInstaller.php @@ -48,6 +48,8 @@ public function configureMysqlAffinity(): void { public function installDatabase(): bool { $db = $this->databaseName; $dump = $this->dumpFile; + $dbHost = $this->options->dbHost; + invariant( $db !== null && $dump !== null, 'database and dump must be specified', @@ -57,7 +59,7 @@ public function installDatabase(): bool { return false; } - $conn = mysql_connect('127.0.0.1', $db, $db); + $conn = mysql_connect($dbHost, $db, $db); $db_selected = mysql_select_db($db, $conn); if ($conn === false || $db_selected === false) { $this->createMySQLDatabase(); @@ -86,7 +88,7 @@ public function installDatabase(): bool { '|'. $sed. Utils::EscapeCommand( - Vector {'mysql', '-h', '127.0.0.1', $db, '-u', $db, '-p'.$db}, + Vector {'mysql', '-h', $dbHost.'', $db, '-u', $db, '-p'.$db}, ), $output, $ret, @@ -112,7 +114,7 @@ private function getRootConnection(): resource { fprintf(STDERR, '%s', 'MySQL admin password: '); $this->password = trim(fgets(STDIN)); } - $conn = mysql_connect('127.0.0.1', $this->username, $this->password); + $conn = mysql_connect($this->options->dbHost, $this->username, $this->password); if ($conn === false) { throw new Exception('Failed to connect: '.mysql_error()); } @@ -121,7 +123,7 @@ private function getRootConnection(): resource { private function checkMySQLConnectionLimit(): void { $conn = - mysql_connect('127.0.0.1', $this->getUsername(), $this->getPassword()); + mysql_connect($this->options->dbHost, $this->getUsername(), $this->getPassword()); if ($conn === false) { throw new Exception('Failed to connect: '.mysql_error()); } @@ -151,7 +153,7 @@ private function createMySQLDatabase(): void { STDERR, '%s', "Can't connect to database ". - "(mysql -h 127.0.0.1 -p$db -u $db $db). This can be ". + "(mysql -h $this->options->dbHost -p$db -u $db $db). This can be ". "fixed for you.\n", ); $conn = $this->getRootConnection(); @@ -178,7 +180,7 @@ private function createMySQLDatabase(): void { $conn, ); mysql_query( - "GRANT ALL PRIVILEGES ON $edb.* TO '$edb'@127.0.0.1 ". + "GRANT ALL PRIVILEGES ON $edb.* TO '$edb'@'$this->options->dbHost' ". "IDENTIFIED BY '$edb'", $conn, ); diff --git a/base/PerfOptions.php b/base/PerfOptions.php index 789c478..e39f243 100644 --- a/base/PerfOptions.php +++ b/base/PerfOptions.php @@ -122,6 +122,8 @@ final class PerfOptions { public bool $notBenchmarking = false; + public string $dbHost = '127.0.0.1'; //The hostname/IP of server which hosts the database. + private array $args; private Vector $notBenchmarkingArgs = Vector {}; @@ -183,6 +185,7 @@ public function __construct(Vector $argv) { 'daemon-files', // daemon output goes to files in the temp directory 'temp-dir:', // temp directory to use; if absent one in /tmp is made 'src-dir:', // location for source to copy into tmp dir instead of ZIP + 'db-host:', 'server-threads:', 'client-threads:', }; @@ -324,7 +327,12 @@ public function __construct(Vector $argv) { $this->daemonOutputToFile = $this->getBool('daemon-files'); $argTempDir = $this->getNullableString('temp-dir'); - + + $host = $this->getNullableString('db-host'); + if ($host) { + $this->dbHost = $host; + } + if(array_key_exists('server-threads', $o)){ $this->serverThreads = $this->args['server-threads']; } diff --git a/targets/drupal7/Drupal7Target.php b/targets/drupal7/Drupal7Target.php index eb2ccba..3c1387c 100644 --- a/targets/drupal7/Drupal7Target.php +++ b/targets/drupal7/Drupal7Target.php @@ -36,6 +36,11 @@ public function install(): void { $this->getSourceRoot().'/sites/default/settings.php', ); + $file = $this->getSourceRoot().'/sites/default/settings.php'; + $file_contents = file_get_contents($file); + $file_contents = str_replace('__DB_HOST__', $this->options->dbHost, $file_contents ); + file_put_contents($file, $file_contents); + (new DatabaseInstaller($this->options)) ->setDatabaseName('drupal_bench') ->setDumpFile(__DIR__.'/dbdump.sql.gz') diff --git a/targets/drupal7/settings.php.gz b/targets/drupal7/settings.php.gz index 575f1a9..1bf7750 100644 Binary files a/targets/drupal7/settings.php.gz and b/targets/drupal7/settings.php.gz differ diff --git a/targets/drupal8/Drupal8Target.php b/targets/drupal8/Drupal8Target.php index 8f45940..32e76d1 100644 --- a/targets/drupal8/Drupal8Target.php +++ b/targets/drupal8/Drupal8Target.php @@ -46,6 +46,10 @@ public function install(): void { __DIR__.'/settings/settings.php', $this->getSourceRoot().'/sites/default/settings.php', ); + $file = $this->getSourceRoot().'/sites/default/settings.php'; + $file_contents = file_get_contents($file); + $file_contents = str_replace('__DB_HOST__', $this->options->dbHost, $file_contents ); + file_put_contents($file, $file_contents); copy( __DIR__.'/settings/setup.php', $this->getSourceRoot().'/sites/default/setup.php', diff --git a/targets/drupal8/settings/settings.php b/targets/drupal8/settings/settings.php index 6dd31a2..c76c3c9 100644 --- a/targets/drupal8/settings/settings.php +++ b/targets/drupal8/settings/settings.php @@ -678,7 +678,7 @@ 'username' => 'drupal_bench', 'password' => 'drupal_bench', 'prefix' => '', - 'host' => '127.0.0.1', + 'host' => '__DB_HOST__', 'port' => '3306', 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', 'driver' => 'mysql', diff --git a/targets/magento1/Magento1Target.php b/targets/magento1/Magento1Target.php index 1d21bea..aba4b3e 100644 --- a/targets/magento1/Magento1Target.php +++ b/targets/magento1/Magento1Target.php @@ -98,6 +98,10 @@ public function install(): void { __DIR__.'/local.xml', $this->getSourceRoot().'/app/etc/local.xml', ); + $file = $this->getSourceRoot().'/app/etc/local.xml'; + $file_contents = file_get_contents($file); + $file_contents = str_replace('__DB_HOST__', $this->options->dbHost, $file_contents ); + file_put_contents($file, $file_contents); return; } @@ -127,7 +131,7 @@ public function install(): void { private function getInstallerArgs(): array { $url = 'http://'.gethostname().':'.PerfSettings::HttpPort().'/'; return array( - 'db_host' => '127.0.0.1', + 'db_host' => $this->options->dbHost, 'db_name' => $this->getDatabaseName(), 'db_user' => $this->installer->getUsername(), 'db_pass' => $this->installer->getPassword(), diff --git a/targets/magento1/local.xml b/targets/magento1/local.xml index 4da021e..0e15102 100755 --- a/targets/magento1/local.xml +++ b/targets/magento1/local.xml @@ -40,7 +40,7 @@ - + diff --git a/targets/mediawiki/LocalSettings.php b/targets/mediawiki/LocalSettings.php index c0fcefc..f2a57ef 100644 --- a/targets/mediawiki/LocalSettings.php +++ b/targets/mediawiki/LocalSettings.php @@ -55,7 +55,7 @@ ## Database settings $wgDBtype = "mysql"; -$wgDBserver = "127.0.0.1"; +$wgDBserver = "__DB_HOST__"; $wgDBname = "mw_bench"; $wgDBuser = "mw_bench"; $wgDBpassword = "mw_bench"; diff --git a/targets/mediawiki/MediaWikiTarget.php b/targets/mediawiki/MediaWikiTarget.php index 66a35fc..c870942 100644 --- a/targets/mediawiki/MediaWikiTarget.php +++ b/targets/mediawiki/MediaWikiTarget.php @@ -39,8 +39,13 @@ public function install(): void { // we're in repo-auth mode, the generated files end up in the repo $cache_dir = $this->getSourceRoot().'/mw-cache'; mkdir($cache_dir); - copy(__DIR__.'/LocalSettings.php', $this->getSourceRoot().'/LocalSettings.php'); + + $file = $this->getSourceRoot().'/LocalSettings.php'; + $file_contents = file_get_contents($file); + $file_contents = str_replace('__DB_HOST__', $this->options->dbHost, $file_contents ); + file_put_contents($file, $file_contents); + file_put_contents( $this->getSourceRoot().'/LocalSettings.php', '$wgCacheDirectory="'.$cache_dir.'";', diff --git a/targets/sugarcrm/SugarCRMTarget.php b/targets/sugarcrm/SugarCRMTarget.php index 4cf1959..6818631 100644 --- a/targets/sugarcrm/SugarCRMTarget.php +++ b/targets/sugarcrm/SugarCRMTarget.php @@ -22,6 +22,10 @@ public function install(): void { } copy(__DIR__.'/config.php', $this->getSourceRoot().'/config.php'); + $file = $this->getSourceRoot().'/config.php'; + $file_contents = file_get_contents($file); + $file_contents = str_replace('__DB_HOST__', $this->options->dbHost, $file_contents ); + file_put_contents($file, $file_contents); if ($this->options->skipDatabaseInstall) { return; diff --git a/targets/sugarcrm/config.php b/targets/sugarcrm/config.php index 3408dcf..969a8a3 100644 --- a/targets/sugarcrm/config.php +++ b/targets/sugarcrm/config.php @@ -52,7 +52,7 @@ 'datef' => 'm/d/Y', 'dbconfig' => array ( - 'db_host_name' => '127.0.0.1', + 'db_host_name' => '__DB_HOST__', 'db_host_instance' => 'SQLEXPRESS', 'db_user_name' => 'sugarcrm', 'db_password' => 'sugarcrm', diff --git a/targets/wordpress/WordpressTarget.php b/targets/wordpress/WordpressTarget.php index f773235..df9c963 100644 --- a/targets/wordpress/WordpressTarget.php +++ b/targets/wordpress/WordpressTarget.php @@ -30,6 +30,11 @@ public function install(): void { copy(__DIR__.'/wp-config.php', $this->getSourceRoot().'/wp-config.php'); + $file = $this->getSourceRoot().'/wp-config.php'; + $file_contents = file_get_contents($file); + $file_contents = str_replace('__DB_HOST__', $this->options->dbHost, $file_contents ); + file_put_contents($file, $file_contents); + $created_database = (new DatabaseInstaller($this->options)) ->setDatabaseName('wp_bench') @@ -45,7 +50,7 @@ public function install(): void { : PerfSettings::HttpPort(); $root = 'http://'.gethostname().':'.$visible_port; - $conn = mysql_connect('127.0.0.1', 'wp_bench', 'wp_bench'); + $conn = mysql_connect($this->options->dbHost, 'wp_bench', 'wp_bench'); $db_selected = mysql_select_db('wp_bench', $conn); $result = mysql_query( 'UPDATE wp_options '. diff --git a/targets/wordpress/wp-config.php b/targets/wordpress/wp-config.php index bd89a31..b36c90f 100644 --- a/targets/wordpress/wp-config.php +++ b/targets/wordpress/wp-config.php @@ -42,7 +42,7 @@ define('DB_PASSWORD', 'wp_bench'); /** MySQL hostname */ -define('DB_HOST', '127.0.0.1'); +define('DB_HOST', '__DB_HOST__'); ////////////////////////////////////////////// ///// END CHANGES TO DEFAULT CONFIG FILE /////