projects
/
cloudstore.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rename Couchbase to Store
[cloudstore.git]
/
rsync-piper.pl
diff --git
a/rsync-piper.pl
b/rsync-piper.pl
index
fc05140
..
ed6d11b
100755
(executable)
--- a/
rsync-piper.pl
+++ b/
rsync-piper.pl
@@
-9,14
+9,16
@@
use IO::Select;
use Time::HiRes;
use Data::Dump qw(dump);
use English;
use Time::HiRes;
use Data::Dump qw(dump);
use English;
+use Module::Refresh;
use lib 'lib';
use lib 'lib';
-use
CloudStore::JSON
;
-use CloudStore::
dedup
;
+use
WarnColor
;
+use CloudStore::
Store
;
my $dir = $ENV{RSYNC_DIR} || '/srv/cloudstore';
my $port = $ENV{RSYNC_PORT} || 6501;
my $users = "users";
my $dir = $ENV{RSYNC_DIR} || '/srv/cloudstore';
my $port = $ENV{RSYNC_PORT} || 6501;
my $users = "users";
+my $default_quota = $ENV{QUOTA} || 200 * 1024; # 200 Kb for test.sh
my $log_fifo = "$dir/var/$port.log";
my $pid_file = "$dir/var/$port.pid";
my $log_fifo = "$dir/var/$port.log";
my $pid_file = "$dir/var/$port.pid";
@@
-54,6
+56,8
@@
if ( $ENV{SQL} ) {
exit 1;
}
exit 1;
}
+my $store = CloudStore::Store->new;
+
mkdir "$dir/var" if ! -e "$dir/var";
unlink $log_fifo if -f $log_fifo;
mkdir "$dir/var" if ! -e "$dir/var";
unlink $log_fifo if -f $log_fifo;
@@
-81,8
+85,8
@@
pid file = $pid_file
# don't check secrets file permission (uid)
strict modes = no
# don't check secrets file permission (uid)
strict modes = no
-#pre-xfer exec = /srv/cloudstore/pre-xfer.sh
-#post-xfer exec = /srv/cloudstore/post-xfer.sh
+pre-xfer exec = /srv/cloudstore/rsync-xfer-trigger.pl
+post-xfer exec = /srv/cloudstore/rsync-xfer-trigger.pl
};
};
@@
-107,6
+111,17
@@
__RSYNC_MODULE__
print "INFO: added $login = $auth_users\n";
print "INFO: added $login = $auth_users\n";
+ my $quota = $default_quota;
+ $quota = read_file("$path/quota") * 1 if -e "$path/quota";
+
+ $store->user_set({
+ login => $login,
+ path => $path,
+ secrets => [ @secrets ],
+ quota => $quota,
+ port => $port,
+ });
+
} else {
warn "skipped $login: $!";
}
} else {
warn "skipped $login: $!";
}
@@
-116,22
+131,48
@@
__RSYNC_MODULE__
write_file $cfg_file, $rsync_config;
warn "created $cfg_file ", -s $cfg_file, " bytes\n";
write_file $cfg_file, $rsync_config;
warn "created $cfg_file ", -s $cfg_file, " bytes\n";
-if ( -e $pid_file ) {
+sub rsync_running_pid {
+ return unless -e $pid_file;
my $pid = read_file $pid_file;
chomp($pid);
my $pid = read_file $pid_file;
chomp($pid);
+ return $pid;
+}
+
+if ( my $pid = rsync_running_pid ) {
if ( kill 0, $pid ) {
warn "found rsync pid $pid\n";
if ( kill 0, $pid ) {
warn "found rsync pid $pid\n";
+=for kill-rsync
kill 2, $pid;
while ( -e $pid_file ) {
warn "waiting for rsync to die...\n";
sleep 1;
}
kill 2, $pid;
while ( -e $pid_file ) {
warn "waiting for rsync to die...\n";
sleep 1;
}
+
+ open(my $fifo, '<', $log_fifo);
+ while ( kill 0, $pid ) {
+ my $line = <$fifo>;
+ warn "<<< $line\n";
+ }
+
kill 0, $pid && die "can't kill it!";
kill 0, $pid && die "can't kill it!";
+=cut
} else {
unlink $pid_file;
}
}
} else {
unlink $pid_file;
}
}
+use POSIX ":sys_wait_h";
+sub REAPER {
+ my $child;
+ while ((my $waitedpid = waitpid(-1,WNOHANG)) > 0) {
+ warn "reaped $waitedpid" . ($? ? " with exit $?" : '');
+ }
+ $SIG{CHLD} = \&REAPER; # loathe SysV
+}
+
+$SIG{CHLD} = \&REAPER;
+
+
if ( ! -e $pid_file ) {
my $exec = "$rsync --daemon --config $cfg_file --no-detach --port=$port";
warn "START $exec\n";
if ( ! -e $pid_file ) {
my $exec = "$rsync --daemon --config $cfg_file --no-detach --port=$port";
warn "START $exec\n";
@@
-155,12
+196,13
@@
$gearman->job_servers('127.0.0.1:4730');
=cut
while(1) {
=cut
while(1) {
- warn "# reading log output from $log_fifo\n";
+ die "no rsync running" unless kill 0, rsync_running_pid;
+ warn "waiting for log from $log_fifo\n";
open(my $fifo, '<', $log_fifo);
while( my $line = <$fifo> ) {
open(my $fifo, '<', $log_fifo);
while( my $line = <$fifo> ) {
-
die $line if $line =~ /rsync error:/
;
+
Module::Refresh->refresh
;
chomp $line;
chomp $line;
-
print
$line, $/;
+
warn
$line, $/;
if ( $line =~ /transfer-log:(.+)/ ) {
my $transfer = $1;
if ( $line =~ /transfer-log:(.+)/ ) {
my $transfer = $1;
@@
-183,14
+225,12
@@
while(1) {
print ">>> data ",dump( \%data ) if $ENV{DEBUG};
print ">>> data ",dump( \%data ) if $ENV{DEBUG};
- CloudStore::dedup::data \%data; # uses deleted json files!
-
- my $json = CloudStore::JSON::rsync_transfer \%data;
-
+ $store->transfer( \%data );
=for gearman
$gearman->dispatch_background( 'rsync_transfer' => $json );
=cut
=for gearman
$gearman->dispatch_background( 'rsync_transfer' => $json );
=cut
+ die "no rsync running" unless kill 0, rsync_running_pid;
}
}
close($fifo);
}
}
close($fifo);