[MediaWiki-commits] [Gerrit] operations/puppet[production]: Create script for automatic reload of categories

2017-11-29 Thread Gehel (Code Review)
Gehel has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/392736 )

Change subject: Create script for automatic reload of categories
..


Create script for automatic reload of categories

Bug: T173772
Change-Id: I96e0863aff73a3cece8c93c8f03ee4901759b7b1
---
A modules/wdqs/files/cron/reloadCategories.sh
M modules/wdqs/manifests/gui.pp
M modules/wdqs/manifests/init.pp
A modules/wdqs/templates/gui_vars.erb
M modules/wdqs/templates/vars.yaml.erb
5 files changed, 72 insertions(+), 4 deletions(-)

Approvals:
  jenkins-bot: Verified
  Gehel: Looks good to me, approved



diff --git a/modules/wdqs/files/cron/reloadCategories.sh 
b/modules/wdqs/files/cron/reloadCategories.sh
new file mode 100755
index 000..2d21a2d
--- /dev/null
+++ b/modules/wdqs/files/cron/reloadCategories.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# This script is reloading categories into a new namespace
+# NOTE: This should be run under user that has rights to
+# sudo systemctl reload nginx
+if [ -r /etc/wdqs/vars.sh ]; then
+  . /etc/wdqs/vars.sh
+fi
+
+if [ -r /etc/wdqs/gui_vars.sh ]; then
+  . /etc/wdqs/gui_vars.sh
+fi
+
+if [ -z "${DATA_DIR}" -o -z "${LOG_DIR}" -o -z "${DEPLOY_DIR}" ]; then
+   echo "Variables not set up right!"
+   exit 1
+fi
+
+today=$(date -u +'%Y%m%d')
+newNamespace="categories${today}"
+# Drop old dumps
+rm -f "${DATA_DIR}/*-categories.ttl.gz"
+cd $DEPLOY_DIR
+bash createNamespace.sh $newNamespace || exit 1
+# Load the data
+bash forAllCategoryWikis.sh loadCategoryDump.sh $newNamespace >> 
"${LOG_DIR}/${newNamespace}.log"
+# Get old namespace
+oldNamespace=$(cat $ALIAS_FILE | grep categories | cut -d' ' -f2)
+# Switch the map
+# NOTE: right now it overrides the map. If we reuse it for other purposes, 
this needs to be made smarter.
+echo "categories ${newNamespace}" > $ALIAS_FILE
+# Bump nginx to reload config
+sudo systemctl reload nginx
+if [ -n "${oldNamespace}" ]; then
+   # Drop old namespace
+   curl -s -X DELETE 
"http://localhost:/bigdata/namespace/${oldNamespace};
+fi
diff --git a/modules/wdqs/manifests/gui.pp b/modules/wdqs/manifests/gui.pp
index 532c5c2..f677ce0 100644
--- a/modules/wdqs/manifests/gui.pp
+++ b/modules/wdqs/manifests/gui.pp
@@ -3,19 +3,25 @@
 # Provisions WDQS GUI
 #
 # == Parameters:
+# - $logstash_host: Where to send the logs for the service in syslog format
+# - $logstash_syslog_port: port on which to send logs in syslog format
 # - $package_dir:  Directory where the service is installed.
-# GUI files are expected to be under its gui/ directory.
+#   GUI files are expected to be under its gui/ directory.
 # - $data_dir: Where the data is installed.
-# - $logstash_host: Where to send the logs for the service in syslog format.
-#
+# - $log_dir: Directory where the logs go
+# - $username: Username owning the service
+# - $port: main GUI service port
+# - $additional_port: secondary port for internal requests
 class wdqs::gui(
 $logstash_host = undef,
 $logstash_syslog_port = 10514,
 $package_dir = $::wdqs::package_dir,
 $data_dir = $::wdqs::data_dir,
+$log_dir = $::wdqs::log_dir,
 $username = $::wdqs::username,
 $port = 80,
 $additional_port = ,
+$use_git_deploy = $::wdqs::use_git_deploy,
 ) {
 
 $alias_map = "${data_dir}/aliases.map"
@@ -25,7 +31,7 @@
 require => File[$alias_map],
 }
 
-# List of namespace aliases in format: 
+# List of namespace aliases in format:
 # ALIAS REAL_NAME
 # This map is generated manually or by category update script
 file { $alias_map:
@@ -44,4 +50,22 @@
 # Because nginx site creates /var/lib/nginx
 require => Nginx::Site['wdqs'],
 }
+
+file { '/etc/wdqs/gui_vars.sh':
+ensure  => present,
+content => template('wdqs/cron/gui_vars.erb'),
+owner   => 'root',
+group   => 'root',
+mode=> '0644',
+}
+
+file { '/usr/local/bin/reloadCategories.sh':
+ensure  => present,
+source  => 'puppet:///modules/wdqs/cron/reloadCategories.sh',
+owner   => 'root',
+group   => 'root',
+mode=> '0755',
+require => File['/etc/default/gui_vars.sh'],
+}
+
 }
diff --git a/modules/wdqs/manifests/init.pp b/modules/wdqs/manifests/init.pp
index 567660f..8849c6e 100644
--- a/modules/wdqs/manifests/init.pp
+++ b/modules/wdqs/manifests/init.pp
@@ -6,6 +6,7 @@
 # == Parameters:
 # - $logstash_host: hostname where to send logs
 # - $logstash_json_port: port on which to send logs in json format
+# - $use_git_deploy: whether scap deployment is being used
 # - $username: Username owning the service
 # - $package_dir:  Directory where the service should be installed.
 # - $data_dir: Directory where the database should be stored
diff --git a/modules/wdqs/templates/gui_vars.erb 
b/modules/wdqs/templates/gui_vars.erb
new file mode 100644
index 000..6b18fff
--- /dev/null
+++ 

[MediaWiki-commits] [Gerrit] operations/puppet[production]: Create script for automatic reload of categories

2017-11-21 Thread Smalyshev (Code Review)
Smalyshev has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/392736 )

Change subject: Create script for automatic reload of categories
..

Create script for automatic reload of categories

Bug: T173772
Change-Id: I96e0863aff73a3cece8c93c8f03ee4901759b7b1
---
M modules/wdqs/manifests/gui.pp
A modules/wdqs/templates/cron/reloadCategories.sh.erb
M modules/wdqs/templates/vars.yaml.erb
3 files changed, 39 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/36/392736/1

diff --git a/modules/wdqs/manifests/gui.pp b/modules/wdqs/manifests/gui.pp
index 9ed953a..44c2ed8 100644
--- a/modules/wdqs/manifests/gui.pp
+++ b/modules/wdqs/manifests/gui.pp
@@ -39,4 +39,13 @@
 group  => 'wikidev',
 mode   => '0775',
 }
+
+file { '/usr/local/bin/reloadCategories.sh':
+ensure  => present,
+content => template('cron/reloadCategories.sh.erb'),
+owner   => 'root',
+group   => 'root',
+mode=> '0755',
+}
+
 }
diff --git a/modules/wdqs/templates/cron/reloadCategories.sh.erb 
b/modules/wdqs/templates/cron/reloadCategories.sh.erb
new file mode 100755
index 000..7cf8c3d
--- /dev/null
+++ b/modules/wdqs/templates/cron/reloadCategories.sh.erb
@@ -0,0 +1,29 @@
+#!/bin/bash
+# This script is reloading categories into a new namespace
+# NOTE: This should be run under user that has rights to
+# sudo service nginx restart
+if [ -r /etc/wdqs/vars.sh ]; then
+  . /etc/wdqs/vars.sh
+fi
+
+DEPLOY_DIR=${DEPLOY_DIR:-"<%= @package_dir %>"}
+DATA_DIR=${DATA_DIR:-"<%= @data_dir %>"}
+ALIAS_FILE="<%= @alias_map %>"
+
+today=$(date -u +'%Y%m%d')
+newNamespace="categories{$today}"
+# Drop old dumps
+rm -f "${DATA_DIR}/*-categories.ttl.gz"
+# Drop old logs
+rm -f "${DATA_DIR}/categories*.log"
+cd $DEPLOY_DIR
+bash createNamespace.sh $newNamespace || exit 1
+# Load the data
+bash forAllCategoryWikis.sh loadCategoryDump.sh $newNamespace >> 
"${DATA_DIR}/${newNamespace}.log"
+# Get old namespace
+oldNamespace=$(cat $ALIAS_FILE | grep categories | cut -d' ' -f2)
+# Switch the map
+echo "categories ${newNamespace}" > $ALIAS_FILE
+sudo service nginx restart
+# Drop old namespace
+curl -s -X DELETE http://localhost:/bigdata/namespace/${oldNamespace}
\ No newline at end of file
diff --git a/modules/wdqs/templates/vars.yaml.erb 
b/modules/wdqs/templates/vars.yaml.erb
index 3ba5b15..21c6a1f 100644
--- a/modules/wdqs/templates/vars.yaml.erb
+++ b/modules/wdqs/templates/vars.yaml.erb
@@ -1,3 +1,4 @@
 ---
 data_dir: <%= @data_dir %>
 endpoint: <%= @endpoint %>
+package_dir: <%= @package_dir %>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I96e0863aff73a3cece8c93c8f03ee4901759b7b1
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Smalyshev 

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