summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-02-26 15:45:39 -0300
committerSilvio Rhatto <rhatto@riseup.net>2011-02-26 15:45:39 -0300
commitf6eb153b9161237f93d0809b912263fffeec7934 (patch)
tree78b9b4a6a6e05f8d7b285c385089802f761bc5e5
parent6496918aaaf4e153a4ea1f022b6302a94452fdd4 (diff)
downloadpuppet-puppet-f6eb153b9161237f93d0809b912263fffeec7934.tar.gz
puppet-puppet-f6eb153b9161237f93d0809b912263fffeec7934.tar.bz2
Lockfile support for check-puppetd
-rw-r--r--templates/check-puppetd.sh.erb50
1 files changed, 50 insertions, 0 deletions
diff --git a/templates/check-puppetd.sh.erb b/templates/check-puppetd.sh.erb
index 298c2b2..d64c21b 100644
--- a/templates/check-puppetd.sh.erb
+++ b/templates/check-puppetd.sh.erb
@@ -6,17 +6,65 @@
PATH="$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
PID="/var/run/puppet/<%= puppet_agent_name %>.pid"
INIT="/etc/init.d/puppet"
+LOCKFILE="/var/run/puppet/check-puppetd.pid"
function puppet_start {
+
sleep `echo $RANDOM/2000*60 | bc`
$INIT start
+
}
function puppet_restart {
+
$INIT stop
puppet_start
+
+}
+
+function set_lockfile {
+
+ if [ ! -z "$LOCKFILE" ]; then
+ mkdir -p `dirname $LOCKFILE`
+ if ( set -o noclobber; echo "$$" > "$LOCKFILE" ) &> /dev/null; then
+ trap 'unset_lockfile' INT TERM EXIT
+ else
+ echo "Could not create lockfile $LOCKFILE, exiting"
+ exit 1
+ fi
+ fi
+
+}
+
+function unset_lockfile {
+
+ if [ ! -z "$LOCKFILE" ]; then
+ $rm -f $LOCKFILE || echo "Could not remove lockfile $LOCKFILE"
+ fi
+
}
+function check_lockfile {
+
+ local pid process
+
+ if [ ! -z "$LOCKFILE" ] && [ -f "$LOCKFILE" ]; then
+ pid="`cat $LOCKFILE`"
+ process="`ps --no-headers -o comm $pid`"
+ if [ "$?" == "0" ] && [ "`ps --no-headers -o comm $$`" == "$process" ]; then
+ echo "Another backup is running for $LOCKFILE, skipping run"
+ exit
+ else
+ echo "Found old lockfile $LOCKFILE, removing it"
+ unset_lockfile
+ fi
+ fi
+
+}
+
+check_lockfile
+set_lockfile
+
if [ "$1" == "restart" ]; then
puppet_restart
elif [ ! -f "$PID" ]; then
@@ -27,3 +75,5 @@ else
puppet_start
fi
fi
+
+unset_lockfile