From: Dobrica Pavlinusic Date: Sun, 4 Sep 2011 17:29:31 +0000 (+0000) Subject: enforce user quota on rsync xfer hooks X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=8d7f0aed45b97b698cd616fcd3986153be1316a7;p=cloudstore.git enforce user quota on rsync xfer hooks --- diff --git a/rsync-piper.pl b/rsync-piper.pl index bcab4cd..dc7333e 100755 --- a/rsync-piper.pl +++ b/rsync-piper.pl @@ -83,8 +83,8 @@ pid file = $pid_file # 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 }; @@ -130,9 +130,14 @@ __RSYNC_MODULE__ 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); + return $pid; +} + +if ( my $pid = rsync_running_pid ) { if ( kill 0, $pid ) { warn "found rsync pid $pid\n"; kill 2, $pid; @@ -188,11 +193,11 @@ $gearman->job_servers('127.0.0.1:4730'); =cut while(1) { + die "no rsync running" unless kill 0, rsync_running_pid; warn "# reading log output from $log_fifo\n"; open(my $fifo, '<', $log_fifo); while( my $line = <$fifo> ) { Module::Refresh->refresh; - die "ERROR: $line" if $line =~ /rsync error:/; chomp $line; print $line, $/; @@ -222,6 +227,7 @@ while(1) { $gearman->dispatch_background( 'rsync_transfer' => $json ); =cut + die "no rsync running" unless kill 0, rsync_running_pid; } } close($fifo); diff --git a/rsync-xfer-trigger.pl b/rsync-xfer-trigger.pl new file mode 100755 index 0000000..31cf59f --- /dev/null +++ b/rsync-xfer-trigger.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl -T +use warnings; +use strict; + +use Data::Dump qw(dump); + +use lib '/srv/cloudstore/lib'; +use CloudStore::Couchbase; + +my $store = CloudStore::Couchbase->new; + +my $login = $ENV{RSYNC_MODULE_NAME} || die "no RSYNC_MODULE_NAME"; + +my $usage = $store->usage({ login => $login }); +my $user = $store->user_get($login); + +if ( $usage > $user->{quota} ) { + warn "ERROR: $login $usage > quota $user->{quota}"; + exit 1; +} else { + warn "OK: $login $usage < quota $user->{quota}"; + exit 0; +}