LongTask. Old version
From ISPWiki
Please note! BILLmanager 4.0.49 contains updated LongTask. More information can be found here.
LongTask allows to use utility features for long task execution. The main task starts a slave one and leaves the third file descriptor that is used to pass parameters open allowing the master process to get a result. The files in the /usr/local/ispmgr/var/run directory are checked every several minutes. If an unblocked RUN file is found in the first line, LongTask restarts. Parameters are passed to the file as follows:
RUN param1 param2 ... paramN
If a task has been successfully completed, you need to delete the file's content and specify:
OK!\n
If an error occurred, you need to delete the file's content and specify:
ERR error_notification\n
Then call:
/usr/local/ispmgr/sbin/mgrctl -m longtask corresponding_software_name
Use billmgr for BILLmanager.
Example on Perl
#!/usr/bin/perl
open(DEBUG, ">>/tmp/debug.log");
open (FD3, '<&3');
my @ltparams;
my $count = 0;
while (<FD3>) {
chomp;
$ltparams[$count] = $_;
$count = $count + 1;
}
if ($count){
print DEBUG "longtask";
my $res = longtask();
open (FD3, '>&3');
seek(FD3, 0, 0);
truncate(FD3, 0);
if($res){
print FD3 "ERR $res\n";
} else {
print FD3 "OK!\n";
}
system "/usr/local/ispmgr/sbin/mgrctl -m billmgr longtask";
} else {
#it is not LongTask, so you may work in a ordinary course.
}
close(DEBUG);
sub longtask(){
#Here you may read parameters from the @ltparams array
#In case of error, you need to return a non-blank line.
}
