~ubuntu-branches/ubuntu/vivid/gitolite3/vivid-proposed

« back to all changes in this revision

Viewing changes to src/commands/mirror

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2014-05-25 20:09:36 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140525200936-el6hezd1fym50pxh
Tags: 3.6-1
* New upstream release
* Depend on ssh-server instead of openssh-server (Closes: #735176).

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
Usage 2 can be initiated by *any* user who has *any* gitolite access to the
29
29
master server, but it checks that the slave is in one of the slaves options
30
30
before doing the push.
 
31
 
 
32
MIRROR STATUS: To find the status of the last mirror push to any slave, run
 
33
the same command except with 'status' instead of 'push'.  With usage 1, you
 
34
can use the special name "all" to get the status of all slaves for the given
 
35
repo.  (Admins wishing to find the status of all slaves for ALL repos will
 
36
have to script it using the output of "gitolite list-phy-repos".)
31
37
=cut
32
38
 
33
39
usage() if not @ARGV or $ARGV[0] eq '-h';
45
51
    _chdir( $rc{GL_REPO_BASE} );
46
52
    _chdir("$repo.git");
47
53
 
48
 
    if (-f "gl-creator") {
 
54
    if ( -f "gl-creator" ) {
49
55
        # try to propagate the wild repo, including creator name and gl-perms
50
56
        my $creator = `cat gl-creator`; chomp($creator);
51
 
        trace(1, `cat gl-perms 2>/dev/null | ssh $host CREATOR=$creator perms -c \\'$repo\\' 2>/dev/null`);
 
57
        trace( 1, `cat gl-perms 2>/dev/null | ssh $host CREATOR=$creator perms -c \\'$repo\\' 2>/dev/null` );
52
58
    }
53
59
 
54
60
    my $errors = 0;
 
61
    my $glss = '';
55
62
    for (`git push --mirror $host:$repo 2>&1`) {
56
63
        $errors = 1 if $?;
57
64
        print STDERR "$_" if -t STDERR or exists $ENV{GL_USER};
 
65
        $glss .= $_;
58
66
        chomp;
59
67
        if (/FATAL/) {
60
68
            $errors = 1;
63
71
            trace( 1, "mirror: $_" );
64
72
        }
65
73
    }
 
74
    # save the mirror push status for this slave if the word 'fatal' is found,
 
75
    # else remove the status file.  We don't store "success" output messages;
 
76
    # you can always get those from the log files if you really need them.
 
77
    if ( $glss =~ /fatal/i ) {
 
78
        my $glss_prefix = Gitolite::Common::gen_ts() . "\t$ENV{GL_TID}\t";
 
79
        $glss =~ s/^/$glss_prefix/gm;
 
80
        _print("gl-slave-$host.status", $glss);
 
81
    } else {
 
82
        unlink "gl-slave-$host.status";
 
83
    }
 
84
 
66
85
    exit $errors;
 
86
} elsif ($cmd eq 'status') {
 
87
    valid_slave( $host, $repo ) if exists $ENV{GL_USER};
 
88
    # will die if host not in slaves for repo
 
89
 
 
90
    _chdir( $rc{GL_REPO_BASE} );
 
91
    _chdir("$repo.git");
 
92
 
 
93
    $host = '*' if $host eq 'all';
 
94
    map { print_status($_) } sort glob("gl-slave-$host.status");
67
95
}
68
96
 
69
97
sub valid_slave {
75
103
 
76
104
    _die "'$host' not a valid slave for '$repo'" unless $list{$host};
77
105
}
 
106
 
 
107
sub print_status {
 
108
    my $file = shift;
 
109
    return unless -f $file;
 
110
    my $slave = $1 if $file =~ /^gl-slave-(.+)\.status$/;
 
111
    print "----------\n";
 
112
    print "WARNING: previous mirror push to host '$slave' failed, status is:\n";
 
113
    print slurp($file);
 
114
    print "----------\n";
 
115
}