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
+++