Ema has submitted this change and it was merged.

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, 51 insertions(+), 0 deletions(-)

Approvals:
  Ema: Verified; Looks good to me, approved
  Volans: Looks good to me, but someone else must approve



diff --git a/modules/base/files/puppet/run-no-puppet 
b/modules/base/files/puppet/run-no-puppet
new file mode 100644
index 0000000..eb4a15f
--- /dev/null
+++ b/modules/base/files/puppet/run-no-puppet
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# Wrapper to run a given command avoiding races with puppet
+
+if [ -z "$1" ]; then
+    echo "Usage: $0 command" >&2
+    exit 1
+fi
+
+MESSAGE="$0[$$]: $1"
+ATTEMPTS="30"
+
+# Re-enable puppet only if it was disabled by us
+enable_puppet() {
+    jq -r '.disabled_message' < /var/lib/puppet/state/agent_disabled.lock |
+      grep -xq "$MESSAGE" && puppet agent --enable
+}
+
+# Disable puppet setting the reason to $MESSAGE
+puppet agent --disable "$MESSAGE"
+
+# Wait for puppet to finish running, timeout after $ATTEMPTS * 10 seconds
+for i in $(seq $ATTEMPTS); do
+    if [ ! -f "/var/lib/puppet/state/agent_catalog_run.lock" ]; then
+        # Puppet is not running, carry on
+        break
+    fi
+    sleep 10
+done
+
+if [ "$i" -eq "$ATTEMPTS" ]; 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
+"$@"
+RET="$?"
+
+enable_puppet
+
+exit "$RET"
diff --git a/modules/base/manifests/puppet.pp b/modules/base/manifests/puppet.pp
index 752c633..1577adc 100644
--- a/modules/base/manifests/puppet.pp
+++ b/modules/base/manifests/puppet.pp
@@ -76,6 +76,13 @@
         source => 'puppet:///modules/base/puppet/puppet-run',
     }
 
+    file { '/usr/local/sbin/run-no-puppet':
+        mode   => '0550',
+        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: merged
Gerrit-Change-Id: I25e2ad297d38e0578171e07a9f7edf42d90a2d9e
Gerrit-PatchSet: 7
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ema <e...@wikimedia.org>
Gerrit-Reviewer: Alexandros Kosiaris <akosia...@wikimedia.org>
Gerrit-Reviewer: BBlack <bbl...@wikimedia.org>
Gerrit-Reviewer: Ema <e...@wikimedia.org>
Gerrit-Reviewer: Gehel <gleder...@wikimedia.org>
Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org>
Gerrit-Reviewer: Volans <rcocci...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to