summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2008-11-01 22:12:58 +0000
committerivan <ivan>2008-11-01 22:12:58 +0000
commite95a136f9dae69525dd926ce4d3314e407a567c9 (patch)
tree6a39bc6b4bbae7b616ab84526fc2cd230a7cdc84 /FS
parenta20987ec5ea35450afbf311829e48e507099dad4 (diff)
have freeside-cdrd disable itself if there's no appropriate package definition, RT#4184
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Daemon.pm10
-rw-r--r--FS/bin/freeside-cdrd31
2 files changed, 37 insertions, 4 deletions
diff --git a/FS/FS/Daemon.pm b/FS/FS/Daemon.pm
index 7e0d45c..ca18134 100644
--- a/FS/FS/Daemon.pm
+++ b/FS/FS/Daemon.pm
@@ -12,7 +12,10 @@ use Date::Format;
#avoid duplicate code. eventually this should use something from CPAN.
@ISA = qw(Exporter);
-@EXPORT_OK = qw( daemonize1 drop_root daemonize2 sigint sigterm logfile );
+@EXPORT_OK = qw(
+ daemonize1 drop_root daemonize2 myexit logfile sigint sigterm
+);
+%EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] );
$pid_dir = '/var/run';
@@ -74,6 +77,11 @@ sub sigterm { $sigterm; }
sub logfile { $logfile = shift; } #_logmsg('test'); }
+sub myexit {
+ unlink $pid_file if -e $pid_file;
+ exit;
+}
+
sub _die {
my $msg = shift;
unlink $pid_file if -e $pid_file;
diff --git a/FS/bin/freeside-cdrd b/FS/bin/freeside-cdrd
index ef420b5..882fd54 100644
--- a/FS/bin/freeside-cdrd
+++ b/FS/bin/freeside-cdrd
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
-use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm);
+use FS::Daemon ':all'; #daemonize1 drop_root daemonize2 myexit logfile sig*
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearch ); #qsearchs);
#use FS::cdr;
@@ -20,6 +20,9 @@ logfile( "%%%FREESIDE_LOG%%%/cdrd-log.". $FS::UID::datasrc );
daemonize2();
+die "not running; no voip_cdr package defs w/ bill_every_call and customer pkgs"
+ unless _shouldrun();
+
#--
my $addl_from =
@@ -66,7 +69,7 @@ while (1) {
$found = 1;
- my $work_cust_pkg = $cust_pkg;
+ #my $work_cust_pkg = $cust_pkg;
my $cust_main = $cust_pkg->cust_main;
@@ -81,13 +84,35 @@ while (1) {
}
- die "exiting" if sigterm() || sigint();
+ myexit() if sigterm() || sigint();
sleep 5; # unless $found;
}
#--
+sub _shouldrun {
+
+ my $extra_sql =
+ ' AND 0 < ( SELECT COUNT(*) FROM cust_pkg
+ WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+ AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+ )
+ ';
+
+ my @part_pkg =
+ grep $_->option('bill_every_call', 'hush'),
+ qsearch({
+ 'table' => 'part_pkg',
+ 'hashref' => { 'plan' => 'voip_cdr' },
+ 'extra_sql' => $extra_sql,
+ })
+ ;
+
+ scalar(@part_pkg);
+
+}
+
sub usage {
die "Usage:\n\n freeside-prepaidd user\n";
}