From 1f77a77fefea93be7380eb4735837d02f2bdafc8 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 21 Aug 2010 18:05:08 -0300 Subject: Fixing lockfile checks for rsync handler --- files/handlers/rsync | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/files/handlers/rsync b/files/handlers/rsync index 9f4590e..ba7dd89 100644 --- a/files/handlers/rsync +++ b/files/handlers/rsync @@ -847,7 +847,13 @@ function test_connect { function set_lockfile { if [ ! -z "$lockfile" ]; then - $touch $lockfile || warning "Could not create lockfile $lockfile" + mkdir -p `dirname $lockfile` + if ( set -o noclobber; echo "$$" > "$lockfile" ) &> /dev/null; then + trap 'rm -f "$lockfile"' INT TERM EXIT + else + info "Could not create lockfile $lockfile, exiting" + exit + fi fi } @@ -860,6 +866,23 @@ function unset_lockfile { } +function check_lockfile { + + local pid + + if [ ! -z "$lockfile" ] && [ -f "$lockfile" ]; then + pid="`cat $lockfile`" + if ps $pid &> /dev/null; then + info "Another backup is running for $lockfile, skipping run" + exit + else + info "Found old lockfile $lockfile, removing it" + unset_lockfile + fi + fi + +} + function set_filelist { filelist_flag="" @@ -1045,6 +1068,7 @@ function end_mux { # the backup procedure eval_config +check_lockfile set_lockfile set_rsync_options start_mux -- cgit v1.2.3