From c2bfdee61fbf96c5fd286b2fe810b138128b5877 Mon Sep 17 00:00:00 2001 From: dpavlin Date: Wed, 18 Jan 2006 15:16:31 +0000 Subject: [PATCH] r9051@llin: dpavlin | 2006-01-18 16:16:23 +0100 added File::Pid to prevent two copies running at same time git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@289 8392b6e1-25fa-0310-8288-cc32f8e212ea --- bin/BackupPC_incPartsUpdate | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bin/BackupPC_incPartsUpdate b/bin/BackupPC_incPartsUpdate index fa89979..7f7313c 100755 --- a/bin/BackupPC_incPartsUpdate +++ b/bin/BackupPC_incPartsUpdate @@ -16,6 +16,24 @@ use Archive::Tar::Streamed; use Algorithm::Diff; use Getopt::Std; use File::Slurp; +use File::Pid; + +my $pid_path = abs_path($0); +$pid_path =~ s/\W+/_/g; + +my $pidfile = new File::Pid({ + file => "/tmp/$pid_path", +}); + +if (my $pid = $pidfile->running ) { + die "$0 already running: $pid\n"; +} elsif ($pidfile->pid ne $$) { + $pidfile->remove; + $pidfile = new File::Pid; +} + +print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n"; +$pidfile->write; my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib"; my %Conf = $bpc->Conf(); -- 2.20.1