X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FSystem%2FTaskServer.pm;h=e410e731117dac3540e13695ec9837c3c025bd4a;hb=09c8c053181f182143beff935d011af15afddb01;hp=df67523ec08eccc8c39c4b9f0123d7404f1f8053;hpb=ecb08b787b2d44e2158c4b0f47d3989bbfe11429;p=kivitendo-erp.git diff --git a/SL/System/TaskServer.pm b/SL/System/TaskServer.pm index df67523ec..e410e7311 100644 --- a/SL/System/TaskServer.pm +++ b/SL/System/TaskServer.pm @@ -10,7 +10,7 @@ use Rose::Object::MakeMethods::Generic ( use File::Slurp; use File::Spec::Functions qw(:ALL); -use File::Temp qw(tempfile); +use File::Temp; use SL::System::Process; @@ -20,6 +20,8 @@ use constant { ERR_PROCESS => -2, }; +use constant PID_BASE => "users/pid"; + sub status { my ($self) = @_; @@ -41,6 +43,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) = @_; @@ -65,8 +73,7 @@ sub _read_pid { my $exe_dir = SL::System::Process->exe_dir; foreach my $conf (qw(kivitendo.conf lx_office.conf kivitendo.conf.default)) { - my $pid_file_name = join '.', splitdir($exe_dir), "config.${conf}.pid"; - my $pid_file_path = catfile(catdir($exe_dir, 'users', 'pid'), $pid_file_name); + my $pid_file_path = catfile(catdir($exe_dir, splitdir(PID_BASE())), "config.${conf}.pid"); return join('', read_file($pid_file_path)) * 1 if -f $pid_file_path; } @@ -75,12 +82,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));