Tim Landscheidt has uploaded a new change for review.

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


Change subject: Add script sql to Tools.
......................................................................

Add script sql to Tools.

The script allows users to just name the database they want to connect
to without having to look up the server it is stored on.

Bug: 48627
Change-Id: Ie111a5adad4c6378ed71825394548f47d4991eaf
---
A modules/toollabs/files/sql
M modules/toollabs/manifests/exec_environ.pp
2 files changed, 46 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/47/64847/1

diff --git a/modules/toollabs/files/sql b/modules/toollabs/files/sql
new file mode 100755
index 0000000..6dde329
--- /dev/null
+++ b/modules/toollabs/files/sql
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+function check_host () {
+    for HOST_I in enwiki bgwiki bgwiktionary cswiki enwikiquote \
+                  enwiktionary eowiki fiwiki idwiki itwiki nlwiki \
+                  nowiki plwiki ptwiki svwiki thwiki trwiki zhwiki \
+                  commonswiki dewiki wikidatawiki; do
+        if [ "$1" = "$HOST_I" ]; then
+            return 0
+        fi
+    done
+
+    return 1
+}
+
+# No database name or extra parameters given?
+if [ $# -eq 0 ] || [ $# -gt 2 ]; then
+    echo "Usage: $0 DATABASE [COMMAND]" >&2
+    exit 1
+fi
+
+# Database name doesn't end up with "_p"?
+HOST="${1%_p}"
+if [ "$1" = "$HOST" ]; then
+    echo "$0: Database name '$1' doesn't end with '_p'." >&2
+    exit 1
+fi
+
+# Host in list of replicated databases?
+if ! check_host "$HOST"; then
+    echo "$0: Database '$1' hasn't been replicated to Tools yet." >&2
+    exit 1
+fi
+
+# Call mysql.
+if [ $# -eq 1 ]; then
+    exec mysql -ch "$HOST.labsdb" "$1"
+else
+    exec mysql -ch "$HOST.labsdb" "$1" -e "$2"
+fi
diff --git a/modules/toollabs/manifests/exec_environ.pp 
b/modules/toollabs/manifests/exec_environ.pp
index 75461dd..f2732cf 100644
--- a/modules/toollabs/manifests/exec_environ.pp
+++ b/modules/toollabs/manifests/exec_environ.pp
@@ -94,6 +94,12 @@
   sysctl { "vm.overcommit_memory": value => 2 }
   sysctl { "vm.overcommit_ratio": value => 95 }
 
+  file { "/usr/local/bin/sql":
+    ensure => file,
+    mode => "0555",
+    source => "puppet:///files/toollabs/sql";
+  }
+
   # TODO: quotas
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie111a5adad4c6378ed71825394548f47d4991eaf
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Tim Landscheidt <t...@tim-landscheidt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to