Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow connecting to a host on a different server #552

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 43 additions & 14 deletions utils/setup.php
Expand Up @@ -80,23 +80,28 @@

$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;

if ($aCMDResult['create-db'] || $aCMDResult['all']) {
echo "Create DB\n";
$bDidSomething = true;
$oDB = DB::connect(CONST_Database_DSN, false);
if (!PEAR::isError($oDB)) {
fail('database already exists ('.CONST_Database_DSN.')');
}
passthruCheckReturn('createdb -E UTF-8 -p '.$aDSNInfo['port'].' '.$aDSNInfo['database']);

passthruCheckReturn(implode(' ', array(
'createdb -E UTF-8',
'-p ' . $aDSNInfo['port'],
'-h ' . $aDSNInfo['hostspec'],
'-U ' . $aDSNInfo['username'],
$aDSNInfo['database']
)));
}

if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
echo "Setup DB\n";
$bDidSomething = true;

// TODO: path detection, detection memory, etc.
//
$oDB =& getDB();

$fPostgresVersion = getPostgresVersion($oDB);
Expand Down Expand Up @@ -148,8 +153,10 @@
// is only defined in the subsequently called create_tables.
// Create dummies here that will be overwritten by the proper
// versions in create-tables.
pgsqlRunScript('CREATE TABLE place_boundingbox ()');
pgsqlRunScript('create type wikipedia_article_match as ()');
pgsqlRunScript('CREATE TABLE IF NOT EXISTS place_boundingbox ()');
if ($oDB->getOne('SELECT exists (SELECT 1 FROM pg_type WHERE pg_type.typname = \'wikipedia_article_match\')') != "t") {
pgsqlRunScript('CREATE TYPE wikipedia_article_match AS ()');
}
}

if ($aCMDResult['import-data'] || $aCMDResult['all']) {
Expand All @@ -176,6 +183,8 @@
$osm2pgsql .= ' -lsc -O gazetteer --hstore --number-processes 1';
$osm2pgsql .= ' -C '.$iCacheMemory;
$osm2pgsql .= ' -P '.$aDSNInfo['port'];
$osm2pgsql .= ' -U '.$aDSNInfo['username'];
$osm2pgsql .= ' -H '.$aDSNInfo['hostspec'];
$osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
passthruCheckReturn($osm2pgsql);

Expand Down Expand Up @@ -558,7 +567,15 @@
if ($aCMDResult['index'] || $aCMDResult['all']) {
$bDidSomething = true;
$sOutputFile = '';
$sBaseCmd = CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$iInstances.$sOutputFile;

$sBaseCmd = implode(' ', array(
CONST_InstallPath.'/nominatim/nominatim -i',
'-d ' . $aDSNInfo['database'],
'-H ' . $aDSNInfo['hostspec'],
'-U ' . $aDSNInfo['username'],
'-P ' . $aDSNInfo['port'],
'-t ' . $iInstances,
));
passthruCheckReturn($sBaseCmd.' -R 4');
if (!$aCMDResult['index-noanalyse']) pgsqlRunScript('ANALYSE');
passthruCheckReturn($sBaseCmd.' -r 5 -R 25');
Expand Down Expand Up @@ -650,15 +667,20 @@
echo "Setup finished.\n";
}


function pgsqlRunScriptFile($sFilename)
{
if (!file_exists($sFilename)) fail('unable to find '.$sFilename);

// Convert database DSN to psql parameters
$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
$sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'];
$sCMD = implode(' ', array(
'psql',
'-p ' . $aDSNInfo['port'],
'-h ' . $aDSNInfo['hostspec'],
'-U ' . $aDSNInfo['username'],
'-d ' . $aDSNInfo['database'],
));

$ahGzipPipes = null;
if (preg_match('/\\.gz$/', $sFilename)) {
Expand Down Expand Up @@ -708,14 +730,21 @@ function pgsqlRunScript($sScript, $bfatal = true)
// Convert database DSN to psql parameters
$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
$sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'];
if ($bfatal && !$aCMDResult['ignore-errors'])
$sCMD = implode(' ', array(
'psql',
'-p ' . $aDSNInfo['port'],
'-h ' . $aDSNInfo['hostspec'],
'-U ' . $aDSNInfo['username'],
'-d ' . $aDSNInfo['database'],
));
if ($bfatal && !$aCMDResult['ignore-errors']) {
$sCMD .= ' -v ON_ERROR_STOP=1';
}
$aDescriptors = array(
0 => array('pipe', 'r'),
1 => STDOUT,
2 => STDERR
);
array('pipe', 'r'),
STDOUT,
STDERR
);
$ahPipes = null;
$hProcess = @proc_open($sCMD, $aDescriptors, $ahPipes);
if (!is_resource($hProcess)) fail('unable to start pgsql');
Expand Down