Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/212475
Change subject: Add a script to disable Puppet temporarily ...................................................................... Add a script to disable Puppet temporarily I am surely not alone in occasionally leaving Puppet disabled for longer than I had intended. This script provides a means of disabling Puppet temporarily. It does so by creating a detached screen session which sleeps for the desired amount of time and then re-enables Puppet. It also leaves a better paper trail by setting a default reason which includes the name of the user disabling Puppet and the time it was disabled. Usage: puppet-disable [DURATION] [REASON] DURATION - Disable Puppet for this much time. Defaults to 1h. REASON - Reason for disabling Puppet. Defaults to a generic message. Examples: Disable Puppet for a day, no reason given: $ puppet-disable 1d Disable Puppet for 30 minutes, with reason: $ puppet-disable 30m "experimenting with HHVM config" Change-Id: I3f89fd339aacac862903974a149b6493cfefb8c9 --- A modules/base/files/puppet/puppet-disable M modules/base/manifests/puppet.pp 2 files changed, 65 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/75/212475/1 diff --git a/modules/base/files/puppet/puppet-disable b/modules/base/files/puppet/puppet-disable new file mode 100755 index 0000000..0cd882c --- /dev/null +++ b/modules/base/files/puppet/puppet-disable @@ -0,0 +1,58 @@ +#!/bin/bash +# -*- coding: utf-8 -*- +# +# puppet-disable - disable Puppet temporarily. +# +# Usage: puppet-disable [DURATION] [REASON] +# +# DURATION - Disable Puppet for this much time. Defaults to 1h. +# REASON - Reason for disabling Puppet. Defaults to a generic +# message. +# +# Examples: +# +# Disable Puppet for a day, no reason given: +# $ puppet-disable 1d +# +# Disable Puppet for 30 minutes, with reason: +# $ puppet-disable 30m "experimenting with HHVM config" +# +# +case "$1" in + [0-9]*) + DURATION="$1" + shift + ;; + -h|--help) + SCRIPT="$(basename "$0")" + echo >&2 "${SCRIPT} - disable Puppet temporarily. " + echo >&2 + echo >&2 "Usage: ${SCRIPT} [DURATION] [REASON] " + echo >&2 + echo >&2 " DURATION - Disable Puppet for this much time. Defaults to 1h. " + echo >&2 " REASON - Reason for disabling Puppet. Defaults to a generic " + echo >&2 " message. " + echo >&2 + echo >&2 "Examples: " + echo >&2 + echo >&2 " Disable Puppet for a day, no reason given: " + echo >&2 " $ ${SCRIPT} 1d " + echo >&2 " " + echo >&2 " Disable Puppet for 30 minutes, with reason: " + echo >&2 " $ ${SCRIPT} 30m \"experimenting with HHVM config\" " + echo >&2 + exit 0 + ;; +esac + +test -f /var/lib/puppet/state/agent_disabled.lock && { + echo >&2 "puppet agent is already disabled!" + exit 1 +} + +TIMESTAMP="$(/bin/date --rfc-3339=seconds --utc)" +DURATION="${DURATION:-1h}" +REASON="${*:-Disabled by ${USER} for ${DURATION} at ${TIMESTAMP}}" +echo "Disabling Puppet for ${DURATION} with reason: \"${REASON}\"." +/usr/bin/sudo /usr/bin/puppet agent --verbose --disable "$REASON" +/usr/bin/screen -d -m /usr/bin/sudo -n /bin/bash -c "/bin/sleep $DURATION ; /usr/bin/puppet agent --enable" diff --git a/modules/base/manifests/puppet.pp b/modules/base/manifests/puppet.pp index 9889f69..352bdc3 100644 --- a/modules/base/manifests/puppet.pp +++ b/modules/base/manifests/puppet.pp @@ -79,6 +79,13 @@ source => 'puppet:///modules/base/puppet/puppet-run', } + file { '/usr/local/sbin/puppet-disable': + source => 'puppet:///modules/base/puppet/puppet-run', + mode => '0555', + owner => 'root', + group => 'root', + } + file { '/etc/cron.d/puppet': mode => '0444', owner => 'root', -- To view, visit https://gerrit.wikimedia.org/r/212475 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3f89fd339aacac862903974a149b6493cfefb8c9 Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits