rsync server now creates user objects
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Sep 2011 16:45:49 +0000 (16:45 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Sep 2011 16:56:40 +0000 (16:56 +0000)
bin/debian-install.sh
rsync-piper.pl

index 358b313..73a7df1 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh -x
 
 sudo apt-get install libautodie-perl libdata-dump-perl libfile-slurp-perl libtime-hires-perl \
-libjson-xs-perl libfile-path-perl
+libjson-xs-perl libfile-path-perl libmodule-refresh-perl
 
index f46d22b..bcab4cd 100755 (executable)
@@ -9,6 +9,7 @@ use IO::Select;
 use Time::HiRes;
 use Data::Dump qw(dump);
 use English;
+use Module::Refresh;
 
 use lib 'lib';
 use CloudStore::Couchbase;
@@ -53,6 +54,8 @@ if ( $ENV{SQL} ) {
        exit 1;
 }
 
+my $store = CloudStore::Couchbase->new;
+
 mkdir "$dir/var" if ! -e "$dir/var";
 
 unlink $log_fifo if -f $log_fifo;
@@ -106,6 +109,18 @@ __RSYNC_MODULE__
 
                print "INFO: added $login = $auth_users\n";
 
+               my $quota = read_file "$path/quota" if -e "$path/quota";
+               chomp $quota && $quota * 1;
+               $quota ||= 100 * 1024; # Kb - XXX default quota
+
+               $store->user_set({
+                       login => $login,
+                       path => $path,
+                       secrets => [ @secrets ],
+                       quota => $quota,
+                       port => $port,
+               });
+
        } else {
                warn "skipped $login: $!";
        }
@@ -175,9 +190,9 @@ $gearman->job_servers('127.0.0.1:4730');
 while(1) {
        warn "# reading log output from $log_fifo\n";
        open(my $fifo, '<', $log_fifo);
-       my $rsync = CloudStore::Couchbase->new;
        while( my $line = <$fifo> ) {
-               die $line if $line =~ /rsync error:/;
+               Module::Refresh->refresh;
+               die "ERROR: $line" if $line =~ /rsync error:/;
                chomp $line;
                print $line, $/;
 
@@ -202,7 +217,7 @@ while(1) {
 
                        print ">>> data ",dump( \%data ) if $ENV{DEBUG};
 
-                       $rsync->transfer( \%data );
+                       $store->transfer( \%data );
 =for gearman
                        $gearman->dispatch_background( 'rsync_transfer' => $json );
 =cut