r9051@llin: dpavlin | 2006-01-18 16:16:23 +0100
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Wed, 18 Jan 2006 15:16:31 +0000 (15:16 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Wed, 18 Jan 2006 15:16:31 +0000 (15:16 +0000)
 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

index fa89979..7f7313c 100755 (executable)
@@ -16,6 +16,24 @@ use Archive::Tar::Streamed;
 use Algorithm::Diff;
 use Getopt::Std;
 use File::Slurp;
 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();
 
 my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib";
 my %Conf = $bpc->Conf();