Ema has uploaded a new change for review.

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

Change subject: base: add run-no-puppet
......................................................................

base: add run-no-puppet

This is a wrapper script to run a given command avoiding races with
puppet.

Change-Id: I25e2ad297d38e0578171e07a9f7edf42d90a2d9e
---
A modules/base/files/puppet/run-no-puppet
M modules/base/manifests/puppet.pp
2 files changed, 45 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/71/311671/1

diff --git a/modules/base/files/puppet/run-no-puppet 
b/modules/base/files/puppet/run-no-puppet
new file mode 100644
index 0000000..669c087
--- /dev/null
+++ b/modules/base/files/puppet/run-no-puppet
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Wrapper to run a given command avoiding races with puppet
+
+if [ -z "$1" ]; then
+    echo "Usage: $0 command" >&2
+    exit 1
+fi
+
+# Re-enable puppet only if it was disabled by us
+enable_puppet() {
+    jq '.disabled_message' < /var/lib/puppet/state/agent_disabled.lock | tr -d 
\" |
+      grep -x "$0: $1" && puppet agent --enable
+}
+
+# Disable puppet setting the reason to the command name
+puppet agent --disable "$0: $1"
+
+# Wait for puppet to finish running, timeout after 120s
+for i in {1..10}; do
+    if [ ! -f "/var/lib/puppet/state/agent_catalog_run.lock" ]; then
+        # Puppet is not running, carry on
+        break
+    fi
+    sleep 12
+done
+
+if [ "$i" -eq 10 ]; then
+    # Puppet did not finish its work within the timeout. Re-enable it and exit
+    enable_puppet
+    echo "$0: timeout reached waiting for puppet to finish running" >&2
+    exit 1
+fi
+
+# Run the command
+"$@"
+
+enable_puppet
diff --git a/modules/base/manifests/puppet.pp b/modules/base/manifests/puppet.pp
index 310f3e9..3141a47 100644
--- a/modules/base/manifests/puppet.pp
+++ b/modules/base/manifests/puppet.pp
@@ -75,6 +75,13 @@
         source => 'puppet:///modules/base/puppet/puppet-run',
     }
 
+    file { '/usr/local/sbin/run-no-puppet':
+        mode   => '0555',
+        owner  => 'root',
+        group  => 'root',
+        source => 'puppet:///modules/base/puppet/run-no-puppet',
+    }
+
     file { '/etc/cron.d/puppet':
         mode    => '0444',
         owner   => 'root',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I25e2ad297d38e0578171e07a9f7edf42d90a2d9e
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ema <e...@wikimedia.org>

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

Reply via email to