Thursday, November 19, 2015

Puppet r10k cron job

It seems I'm continually tweaking the cron job that runs r10k on my Puppet Masters.  It's not quite enough to just run r10k deploy environment -pv since we need to make sure a previous run isn't still running.  Sometimes git will hang as well, hanging the whole process indefinitely, so we need to set a timeout to kill the process.  Lastly, there are PATH issues you have to deal with.  Here's my current script that gets called by a cron job in the pe-puppet user's crontab:
#!/bin/bash

PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin

# Only run if r10k isn't already running, in case a previous run is still going
if ! pgrep -f 'r10k deploy' > /dev/null
then
    timeout -s 9 1200s /usr/local/bin/r10k deploy environment -pv > /tmp/r10k.log 2>&1
fi


No comments: