almost all src/conf: logging totally redone, upgrade doc added

- logs go into $GL_ADMINDIR/logs by default, named by year-month
  - logfile name template (including dir prefix) now in $GL_LOGT
  - two new env vars passed down: GL_TS and GL_LOG (timestamp, logfilename)
  - log messages timestamps more compact, fields tab-delimited
  - old and new SHAs cut to 14 characters
This commit is contained in:
Sitaram Chamarty 2009-09-06 13:34:41 +05:30
parent 455ebe1bc9
commit 804c70f570
7 changed files with 123 additions and 32 deletions

View file

@ -23,9 +23,8 @@ use warnings;
# common definitions
# ----------------------------------------------------------------------------
our $GL_ADMINDIR;
our $GL_CONF_COMPILED;
our $REPO_BASE;
our ($GL_LOGT, $GL_CONF_COMPILED, $REPO_BASE);
our %repos;
my $glrc = $ENV{HOME} . "/.gitolite.rc";
@ -89,18 +88,36 @@ die "$perm access for $repo denied to $user"
or $repos{$repo}{$perm}{'@all'};
# ----------------------------------------------------------------------------
# over to git now
# logging, timestamp. also setup env vars for later
# ----------------------------------------------------------------------------
# ( but first save the reponame; we can save some time later in the hook )
# reponame
$ENV{GL_REPO}=$repo;
# timestamp
my ($s, $min, $h, $d, $m, $y) = (localtime)[0..5];
$y += 1900; $m++; # usual adjustments
for ($s, $min, $h, $d, $m) {
$_ = "0$_" if $_ < 10;
}
$ENV{GL_TS} = "$y-$m-$d.$h:$min:$s";
# substitute template parameters and set the logfile name
$GL_LOGT =~ s/%y/$y/g;
$GL_LOGT =~ s/%m/$m/g;
$GL_LOGT =~ s/%d/$d/g;
$ENV{GL_LOG} = $GL_LOGT;
# if log failure isn't important enough to block access, get rid of all the
# error checking
open my $log_fh, ">>", "$GL_ADMINDIR/log"
open my $log_fh, ">>", $ENV{GL_LOG}
or die "open log failed: $!";
print $log_fh "\n", scalar(localtime), " $ENV{SSH_ORIGINAL_COMMAND} $user\n";
print $log_fh "$ENV{GL_TS}\t$ENV{SSH_ORIGINAL_COMMAND}\t$user\n";
close $log_fh or die "close log failed: $!";
# ----------------------------------------------------------------------------
# over to git now
# ----------------------------------------------------------------------------
$repo = "'$REPO_BASE/$repo.git'";
exec("git", "shell", "-c", "$verb $repo");

View file

@ -41,11 +41,7 @@ use Data::Dumper;
# common definitions
# ----------------------------------------------------------------------------
our $GL_ADMINDIR;
our $GL_CONF;
our $GL_KEYDIR;
our $GL_CONF_COMPILED;
our $REPO_BASE;
our ($GL_ADMINDIR, $GL_CONF, $GL_KEYDIR, $GL_CONF_COMPILED, $REPO_BASE);
my $glrc = $ENV{HOME} . "/.gitolite.rc";
die "parse $glrc failed: " . ($! or $@) unless do $glrc;

View file

@ -3,9 +3,7 @@
use strict;
use warnings;
our $REPO_BASE;
our $GL_ADMINDIR;
our $GL_CONF;
our ($REPO_BASE, $GL_ADMINDIR, $GL_CONF);
# wrapper around mkdir; it's not an error if the directory exists, but it is
# an error if it doesn't exist and we can't create it
@ -31,10 +29,11 @@ unless (-f $glrc) {
die "parse $glrc failed: " . ($! or $@) unless do $glrc;
# mkdir $REPO_BASE, $GL_ADMINDIR if they don't already exist
wrap_mkdir( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
wrap_mkdir($repo_base_abs);
wrap_mkdir($GL_ADMINDIR);
# mkdir $GL_ADMINDIR's subdirs
for my $dir qw(conf doc keydir src) {
for my $dir qw(conf doc keydir logs src) {
wrap_mkdir("$GL_ADMINDIR/$dir");
}
@ -54,13 +53,9 @@ EOF
# finally, any potential changes to src/update-hook.pl must be propagated to
# all the repos' hook directories
my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
# err, no need to get all worked up if you can't CD there -- this may be the
# very first run and it hasn't been created yet
if (chdir("$repo_base_abs")) {
for my $repo (`find . -type d -name "*.git"`) {
chomp ($repo);
system("cp $GL_ADMINDIR/src/update-hook.pl $repo/hooks/update");
chmod 0755, "$repo/hooks/update";
}
chdir("$repo_base_abs") or die "chdir $repo_base_abs failed: $!\n";
for my $repo (`find . -type d -name "*.git"`) {
chomp ($repo);
system("cp $GL_ADMINDIR/src/update-hook.pl $repo/hooks/update");
chmod 0755, "$repo/hooks/update";
}

View file

@ -25,9 +25,7 @@ use warnings;
# common definitions
# ----------------------------------------------------------------------------
our $GL_ADMINDIR;
our $GL_CONF_COMPILED;
our $PERSONAL;
our ($GL_CONF_COMPILED, $PERSONAL);
our %repos;
my $glrc = $ENV{HOME} . "/.gitolite.rc";
@ -70,9 +68,11 @@ for my $refex (@allowed_refs)
{
# if log failure isn't important enough to block pushes, get rid of
# all the error checking
open my $log_fh, ">>", "$GL_ADMINDIR/log"
open my $log_fh, ">>", $ENV{GL_LOG}
or die "open log failed: $!";
print $log_fh "$perm: $ENV{GL_USER} $ENV{GL_REPO} $ref $oldsha $newsha\n";
print $log_fh "$ENV{GL_TS} $perm\t" .
substr($oldsha, 0, 14) . "\t" . substr($newsha, 0, 14) .
"\t$ENV{GL_REPO}\t$ref\t$ENV{GL_USER}\n";
close $log_fh or die "close log failed: $!";
exit 0;
}