[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
locking solved
From: |
raptor |
Subject: |
locking solved |
Date: |
Thu, 4 Oct 2001 15:27:25 +0200 |
hi,
here is my final solution..... of my locking-oddisey :")
see the scripts below....
oops .. the update is triggered only if the commit message beings with -!-
(exclamation mark)
thanx for the help
=====
iVAN
address@hidden
=====
#!/usr/bin/perl
#Author : raptor
use strict;
my $lockfile = '/var/lock/cvs/update.lck';
my $userName = getpwuid($<);
my $updater = '/path/to/updater.pl';
#get the directory we are working on
my ($dir) = $ARGV[0] =~ /^([^\s]+?)\s/;
sub isLocked { -e $lockfile };
sub lock { open FILE, ">$lockfile" or die "Can't create lock file\n" };
#================= MAIN
#get the all info
undef $/;
my $msg = <STDIN>;
#now check to see if the log message begins with '!'
unless ( $msg =~ /Log Message:.!/gs) {
print qq{$userName : $dir
$msg
--------
};
}# we will do our actions then
else {
print "loginfo : -!- used will do update ASAP.....\n";
unless (isLocked()) { print "loginfo: scheduling update...\n"; lock() }
else { print "loginfo : update already scheduled, it is ok don't
worry...\n"};
};
__END__
=head1 DESCRIPTION
Use those scripts so that U can have your main Development
working copy up to date. Primary usefull for Web development.
The first script is attached as log-info script.(see: 'info cvs')
What it does is to create a file whenever commit happen, if
this file is already created it does nothing.
The second script stays up all the time and on every X seconds
checks for this file...
if there is no file it just sleeps X seconds, otherwise it checks
if there are some 'cvs'-processes hanging around and if yes
it sleeps again.
But if there is no such processes it makes an cvs-update.
Why so much trouble ?
'Cause 'cvs' work on a per directory basis i.e. when u make commit
it fires log-info script for every directory that has to be updated
(i.e cvs unlocks only the current cvs-dir on which your log-info
script has been started), so if u want to make cvs-update inside
the log-info script u can't 'cause other directories are locked.
I tried to start cvs-update process via both exec & fork, but the
cvs processes was still hanging around waiting for me to finish.
(Can figure out other way how to run this as stand-alone process!!)
The main problem is to broke parent-child reltionship.
One other solution would be to update only the directory on which
log-info script has been called, which i'm figuring just now
(as I write this docs). This probably will be better solution !!
This will fire too much standalone/outside cvs-updates,
don't know which is worst. One-big or many-small!!
=head2 TODO
- make the second variant i just explained
- make the updater script like a daemon
- create init.d script so it can be executed on bootup
=cut
===================================updater.pl==========================
#!/usr/bin/perl
#Author : raptor
use strict;
my $userName = getpwuid($<);
my $cvs = '/usr/bin/cvs';
my $repo = '/path/to/repository';
my $lockfile = '/var/lock/cvs/update.lck';
my $workcopy = '/cvstest/mytest';
sub isLocked { -e $lockfile };
sub cvsActive { my $pids = `pidof cvs`; chop $pids; $pids };
sub unlock { unlink $lockfile };
sub update {
chdir $workcopy;
system "$cvs -d $repo update -d -A";
print 'ERROR: Can not update the working copy' if $? > 0;
};
#================= MAIN
print "Process-ID : $$\n";
while ( 1 ) {
print '.';
if (isLocked() && ! cvsActive() ) {
update(); unlock();
};
`sleep 5`;#using perl sleep didn't worked !?!!!
};
__END__
- locking solved,
raptor <=