7341: run-deploy.sh retries failed Puppet agent runs. 7341-deploy-retries-puppet-agent-wip
authorBrett Smith <brett@curoverse.com>
Wed, 14 Oct 2015 22:18:58 +0000 (18:18 -0400)
committerBrett Smith <brett@curoverse.com>
Thu, 15 Oct 2015 12:14:54 +0000 (08:14 -0400)
It simply keeps retrying any failure until ten minutes have passed,
per Nico's suggestion in the comments.

Bonus bugfix: make sure run_puppet's ECODE variable gets set to the
exit status of Puppet (or the wrapper script), and not tee.

jenkins/run-deploy.sh

index 49536597b4b2972296718bd92979fe8978f218aa..b81218e53106c5f9bbc9f7ad094463e3c10a5348 100755 (executable)
@@ -64,6 +64,21 @@ EXITCODE=0
 
 COLUMNS=80
 
+PUPPET_AGENT='
+now() { date +%s; }
+let endtime="$(now) + 600"
+while [ "$endtime" -gt "$(now)" ]; do
+    puppet agent --test --detailed-exitcodes
+    agent_exitcode=$?
+    if [ 0 = "$agent_exitcode" ] || [ 2 = "$agent_exitcode" ]; then
+        break
+    else
+        sleep 10s
+    fi
+done
+exit ${agent_exitcode:-99}
+'
+
 title () {
   date=`date +'%Y-%m-%d %H:%M:%S'`
   printf "$date $1\n"
@@ -76,12 +91,12 @@ function run_puppet() {
   title "Running puppet on $node"
   TMP_FILE=`mktemp`
   if [[ "$DEBUG" != "0" ]]; then
-    ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "/usr/bin/puppet agent -t" | tee $TMP_FILE
+    ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" | tee $TMP_FILE
   else
-    ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C "/usr/bin/puppet agent -t" > $TMP_FILE 2>&1
+    ssh -t -p2222 -o "StrictHostKeyChecking no" -o "ConnectTimeout 5" root@$node -C bash -c "'$PUPPET_AGENT'" > $TMP_FILE 2>&1
   fi
 
-  ECODE=$?
+  ECODE=${PIPESTATUS[0]}
   RESULT=$(cat $TMP_FILE)
 
   if [[ "$ECODE" != "255" && ! ("$RESULT" =~ 'already in progress') && "$ECODE" != "2" && "$ECODE" != "0"  ]]; then