2016-09-05 20:14:41 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Reports the hostname of a replica DB server.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2016-09-05 20:14:41 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2016-09-05 20:14:41 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maintenance script that reports the hostname of a replica DB server.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2018-05-24 01:34:01 +00:00
|
|
|
class GetReplicaServer extends Maintenance {
|
2016-09-05 20:14:41 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->addOption( "group", "Query group to check specifically" );
|
2021-11-21 22:04:10 +00:00
|
|
|
$this->addOption( 'cluster', 'Use an external cluster by name', false, true );
|
2016-09-05 20:14:41 +00:00
|
|
|
$this->addDescription( 'Report the hostname of a replica DB server' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2023-08-31 09:21:12 +00:00
|
|
|
$lbf = $this->getServiceContainer()->getDBLoadBalancerFactory();
|
2021-11-21 22:04:10 +00:00
|
|
|
if ( $this->hasOption( 'cluster' ) ) {
|
|
|
|
|
try {
|
|
|
|
|
$lb = $lbf->getExternalLB( $this->getOption( 'cluster' ) );
|
|
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
|
$this->fatalError( 'Error: ' . $e->getMessage() );
|
|
|
|
|
}
|
2016-09-05 20:14:41 +00:00
|
|
|
} else {
|
2021-11-21 22:04:10 +00:00
|
|
|
$lb = $lbf->getMainLB();
|
2016-09-05 20:14:41 +00:00
|
|
|
}
|
2021-11-21 22:04:10 +00:00
|
|
|
|
|
|
|
|
$group = $this->getOption( 'group', false );
|
|
|
|
|
$index = $lb->getReaderIndex( $group );
|
|
|
|
|
if ( $index === false && $group ) {
|
|
|
|
|
// retry without the group; it may not exist
|
|
|
|
|
$index = $lb->getReaderIndex( false );
|
|
|
|
|
}
|
|
|
|
|
if ( $index === false ) {
|
|
|
|
|
$this->fatalError( 'Error: unable to get reader index' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->output( $lb->getServerName( $index ) . "\n" );
|
2016-09-05 20:14:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-05-24 01:34:01 +00:00
|
|
|
$maintClass = GetReplicaServer::class;
|
2016-09-05 20:14:41 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|