X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FSystem%2FTaskServer.pm;h=a37cd03d1a7a9f223c26d3521d09fc203e1c1213;hb=8be0f8a7ff52242c1b38345541796f66891735fa;hp=57d0ba827f4f29b340d98c9b15626d2f1a3897a2;hpb=db7dbf2671f1f6b7bbac2c284308dcd79c427711;p=kivitendo-erp.git diff --git a/SL/System/TaskServer.pm b/SL/System/TaskServer.pm index 57d0ba827..a37cd03d1 100644 --- a/SL/System/TaskServer.pm +++ b/SL/System/TaskServer.pm @@ -10,7 +10,8 @@ use Rose::Object::MakeMethods::Generic ( use File::Slurp; use File::Spec::Functions qw(:ALL); -use File::Temp qw(tempfile); +use File::Temp; +use Sys::Hostname (); use SL::System::Process; @@ -22,6 +23,8 @@ use constant { use constant PID_BASE => "users/pid"; +my $node_id; + sub status { my ($self) = @_; @@ -43,6 +46,12 @@ sub start { return $self->_run_script_command('start'); } +sub start_if_not_running { + my ($self) = @_; + + $self->start unless $self->is_running; +} + sub stop { my ($self) = @_; @@ -57,6 +66,14 @@ sub wake_up { 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 # @@ -76,12 +93,13 @@ sub _read_pid { 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));