Amire80 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300862

Change subject: Split sql to sql and sqlhost
......................................................................

Split sql to sql and sqlhost

Bug: T141255
Change-Id: I8b1ff1acafdd51722ce5259b40710c9c363ddfaf
---
M modules/scap/files/sql
A modules/scap/files/sqlhost
2 files changed, 61 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/62/300862/1

diff --git a/modules/scap/files/sql b/modules/scap/files/sql
index 14b2b6c..c3b564d 100755
--- a/modules/scap/files/sql
+++ b/modules/scap/files/sql
@@ -14,41 +14,24 @@
     echo 'Usage: sql [--write] <dbname> [mysqloptions]'
     exit 0
 elif [ "$db" = "--write" ]; then
-    hostcode="echo \$lb->getServerName(0);"
-
     # Database will be the next parameter
     db=$1
     shift
-else
-    hostcode="echo \$lb->getServerName(\$lb->getReaderIndex());"
-fi
 
-# Look up MySQL host to connect to.  For centralauth the host cannot
-# be determined this way, so we need to use fawiki instead as it is
-# located on the same server in both production and labs.
-# wikishared is hosted on x1 (i.e. without any local wikis), just use
-# meta to lookup the password.
-if [ "$db" = "centralauth" ]; then
-    lookupdb="fawiki"
-elif [ "$db" = "wikishared" ]; then
-    lookupdb="metawiki"
+    hostpass=`./sqlhost --write $db`
 else
-    lookupdb="$db"
+    hostpass=`./sqlhost $db`
 fi
-
-if [ "$db" = "wikishared" ]; then
-    lbcode="\$lb = wfGetLBFactory()->getExternalLB('extension1');"
-else
-    lbcode="\$lb = wfGetLB();"
-fi
-host=`echo $lbcode $hostcode | /usr/local/bin/mwscript eval.php 
--wiki="$lookupdb"`
-pass=`echo 'echo \$wgDBadminpassword;' | /usr/local/bin/mwscript eval.php 
--wiki="$lookupdb"`
 
 if [ $? -ne 0 ]; then
     # PHP error, probably an invalid DB code
-    echo "Error looking up DB \"$db\"" 1>&2
-    exit 1
+    echo "sql: Error looking up DB \"$db\"" 1>&2
+    exit $?
 fi
 
+hostpass=($hostpass)
+host=${hostpass[0]}
+pass=${hostpass[1]}
+
 # Execute mysql.
 exec mysql -u wikiadmin -p$pass -h $host -D $db "$@"
diff --git a/modules/scap/files/sqlhost b/modules/scap/files/sqlhost
new file mode 100755
index 0000000..460407b
--- /dev/null
+++ b/modules/scap/files/sqlhost
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+# This file is managed by Puppet (modules/scap/files/sqlhost).
+
+# Read configuration.
+. /etc/profile.d/mediawiki.sh
+
+# Database that the user wants to read, or a special parameter.
+db=$1
+shift
+
+if [ -z "$db" ] || [ "$db" = "--help" ]; then
+    echo 'Usage: sqlhost [--write] <dbname>'
+    exit 0
+elif [ "$db" = "--write" ]; then
+    hostcode="echo \$lb->getServerName(0);"
+
+    # Database will be the next parameter
+    db=$1
+    shift
+else
+    hostcode="echo \$lb->getServerName(\$lb->getReaderIndex());"
+fi
+
+# Look up MySQL host to connect to.  For centralauth the host cannot
+# be determined this way, so we need to use fawiki instead as it is
+# located on the same server in both production and labs.
+# wikishared is hosted on x1 (i.e. without any local wikis), just use
+# meta to lookup the password.
+if [ "$db" = "centralauth" ]; then
+    lookupdb="fawiki"
+elif [ "$db" = "wikishared" ]; then
+    lookupdb="metawiki"
+else
+    lookupdb="$db"
+fi
+
+if [ "$db" = "wikishared" ]; then
+    lbcode="\$lb = wfGetLBFactory()->getExternalLB('extension1');"
+else
+    lbcode="\$lb = wfGetLB();"
+fi
+host=`echo $lbcode $hostcode | /usr/local/bin/mwscript eval.php 
--wiki="$lookupdb"`
+pass=`echo 'echo \$wgDBadminpassword;' | /usr/local/bin/mwscript eval.php 
--wiki="$lookupdb"`
+
+if [ $? -ne 0 ]; then
+    # PHP error, probably an invalid DB code
+    echo "sqlhost: Error looking up DB \"$db\"" 1>&2
+    exit 1
+fi
+
+echo $host $pass
+

-- 
To view, visit https://gerrit.wikimedia.org/r/300862
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8b1ff1acafdd51722ce5259b40710c9c363ddfaf
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Amire80 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to