Merge branch 'master' into rorcz
[girocco.git] / toolbox / remirror-project.pl
blob98233762f99e10a83eecbfbca3327bd7950cdc1b
1 #!/usr/bin/perl
3 # Initiate a re-mirror of a project
5 use strict;
6 use warnings;
7 use IO::Socket;
8 use lib @basedir@;
10 use Girocco::Config;
11 use Girocco::Project;
13 sub mydie
15 print STDERR "@_\n";
16 exit(255);
19 undef(*CORE::GLOBAL::die);
20 *CORE::GLOBAL::die = \&mydie;
22 my $project = shift @ARGV || die "Please give project name on command line.";
24 my $p = Girocco::Project->load($project) || die "Project '$project' not found!";
26 if (!$p->{mirror}) {
27 die "Project '$project' is a push project, not a mirror project."
30 if ($p->{clone_in_progress} && !$p->{clone_failed}) {
31 die "Project '$project' already has a clone underway at this moment."
34 unlink($p->_clonefail_path);
35 unlink($p->_clonelog_path);
36 my $cp = $p->_clonep_path;
37 open X, '>'.$cp or die "failed to create $cp: $!";
38 close X;
40 my $sock = IO::Socket::UNIX->new($Girocco::Config::chroot.'/etc/taskd.socket') or die "cannot connect to taskd.socket: $!";
41 $sock->print("clone ".$p->{name}."\n");
42 # Just ignore reply, we are going to succeed anyway and the I/O
43 # would apparently get quite hairy.
44 $sock->flush();
45 sleep 2; # *cough*
46 $sock->close();
48 print "Project '$project' remirror initiated.\n";
49 exit 0