use File::Slurp;
use File::Spec::Functions qw(:ALL);
-use File::Temp qw(tempfile);
+use File::Temp;
+use Sys::Hostname ();
use SL::System::Process;
use constant PID_BASE => "users/pid";
+my $node_id;
+
sub status {
my ($self) = @_;
return $self->_run_script_command('start');
}
+sub start_if_not_running {
+ my ($self) = @_;
+
+ $self->start unless $self->is_running;
+}
+
sub stop {
my ($self) = @_;
return kill('ALRM', $pid) ? 1 : undef;
}
+sub node_id {
+ return $node_id if $node_id;
+
+ $node_id = ($::lx_office_conf{task_server} // {})->{node_id} || Sys::Hostname::hostname();
+
+ return $node_id;
+}
+
#
# private methods
#
sub _run_script_command {
my ($self, $command) = @_;
- my ($fh, $file_name) = tempfile();
my $exe = catfile(catdir(SL::System::Process->exe_dir, 'scripts'), 'task_server.pl');
+ my $temp_file = File::Temp->new;
+ my $file_name = $temp_file->filename;
- system "${exe} ${command} >> ${file_name} 2>&1";
+ $temp_file->close;
- $fh->close;
+ system "${exe} ${command} >> ${file_name} 2>&1";
$self->last_command_output(read_file($file_name));