Merge maintenance-work branch:
[lhc/web/wiklou.git] / maintenance / getSlaveServer.php
1 <?php
2 /**
3 * This script reports the hostname of a slave server.
4 *
5 * @file
6 * @ingroup Maintenance
7 */
8
9 require_once( "Maintenance.php" );
10
11 class GetSlaveServer extends Maintenance {
12 public function __construct() {
13 parent::__construct();
14 $this->addParam( "group", "Query group to check specifically" );
15 $this->mDescription = "Report the hostname of a slave server";
16 }
17 public function execute() {
18 global $wgAllDBsAreLocalhost;
19 if( $wgAllDBsAreLocalhost ) {
20 $host = 'localhost';
21 } else {
22 if( $this->hasOption('group') ) {
23 $db = wfGetDB( DB_SLAVE, $this->getOption('group') );
24 $host = $db->getServer();
25 } else {
26 $lb = wfGetLB();
27 $i = $lb->getReaderIndex();
28 $host = $lb->getServerName( $i );
29 }
30 }
31 $this->output( "$host\n" );
32 }
33 }
34
35 $maintClass = "GetSlaveServer";
36 require_once( DO_MAINTENANCE );