Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Adding command line parameter --db-host to specify remote mysql serve…
Browse files Browse the repository at this point in the history
…r. (#79)
  • Loading branch information
kevand900 authored and mofarrell committed Apr 10, 2017
1 parent a73aaeb commit add27b4
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 15 deletions.
14 changes: 8 additions & 6 deletions base/DatabaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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,
);
Expand Down
10 changes: 9 additions & 1 deletion base/PerfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $notBenchmarkingArgs = Vector {};

Expand Down Expand Up @@ -183,6 +185,7 @@ public function __construct(Vector<string> $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:',
};
Expand Down Expand Up @@ -324,7 +327,12 @@ public function __construct(Vector<string> $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'];
}
Expand Down
5 changes: 5 additions & 0 deletions targets/drupal7/Drupal7Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Binary file modified targets/drupal7/settings.php.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions targets/drupal8/Drupal8Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion targets/drupal8/settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion targets/magento1/Magento1Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion targets/magento1/local.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</db>
<default_setup>
<connection>
<host><![CDATA[127.0.0.1]]></host>
<host><![CDATA[__DB_HOST__]]></host>
<username><![CDATA[magento_bench]]></username>
<password><![CDATA[magento_bench]]></password>
<dbname><![CDATA[magento_bench]]></dbname>
Expand Down
2 changes: 1 addition & 1 deletion targets/mediawiki/LocalSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 6 additions & 1 deletion targets/mediawiki/MediaWikiTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'";',
Expand Down
4 changes: 4 additions & 0 deletions targets/sugarcrm/SugarCRMTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion targets/sugarcrm/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion targets/wordpress/WordpressTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 '.
Expand Down
2 changes: 1 addition & 1 deletion targets/wordpress/wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 /////
Expand Down

0 comments on commit add27b4

Please sign in to comment.