6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearchs);
10 # no autoloading just yet
13 my $pid_file = '/var/run/freeside-queued.pid';
15 $SIG{CHLD} = sub { wait }; #zombie prevention
19 $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; };
20 $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; };
22 my $user = shift or die &usage;
26 my $log_file = "/usr/local/etc/freeside/queuelog.";
28 $> = $FS::UID::freeside_uid unless $>;
31 $log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc;
33 $SIG{__DIE__} = \&_die;
34 $SIG{__WARN__} = \&_logmsg;
41 { 'status' => 'new' },
43 'ORDER BY jobnum FOR UPDATE LIMIT 1'
49 my %hash = $job->hash;
50 $hash{'status'} = 'locked';
51 my $ljob = new FS::queue ( \%hash );
52 my $error = $ljob->replace($job);
55 my @args = $ljob->args;
57 #fork a child for each job (up to some maximum perhaps?)
58 #single-threaded for now.
60 my $eval = "&". $ljob->job. '(@args);';
64 warn "job $eval failed";
65 my $hash = $ljob->hash;
66 $hash{'status'} = 'failed';
67 my $fjob = new FS::queue( \%hash );
68 my $error = $fjob->replace($ljob);
76 warn "received TERM signal; exiting\n";
80 warn "received INT signal; exiting\n";
87 time2str("%m%d%Y", time);
92 unlink $pid_file if -e $pid_file;
97 chomp( my $msg = shift );
98 my $log = new IO::File ">>$log_file";
101 print $log "[". time2str("%a %b %e %T %Y",time). "] [$$] $msg\n";
102 flock($log, LOCK_UN);
107 chdir "/" or die "Can't chdir to /: $!";
108 open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
109 defined(my $pid = fork) or die "Can't fork: $!";
111 print "freeside-queued started with pid $pid\n"; #logging to $log_file\n";
112 exit unless $pid_file;
113 my $pidfh = new IO::File ">$pid_file" or exit;
114 print $pidfh "$pid\n";
117 open STDOUT, '>/dev/null'
118 or die "Can't write to /dev/null: $!";
119 setsid or die "Can't start a new session: $!";
120 open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
126 freeside-queued - Job queue daemon
134 Job queue daemon. Should be running at all times.
136 user: from the mapsecrets file - see config.html from the base documentation