Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / SL / System / TaskServer.pm
index 17be8ed..57d0ba8 100644 (file)
@@ -10,6 +10,7 @@ use Rose::Object::MakeMethods::Generic (
 
 use File::Slurp;
 use File::Spec::Functions qw(:ALL);
+use File::Temp qw(tempfile);
 
 use SL::System::Process;
 
@@ -19,6 +20,8 @@ use constant {
   ERR_PROCESS  => -2,
 };
 
+use constant PID_BASE => "users/pid";
+
 sub status {
   my ($self) = @_;
 
@@ -64,8 +67,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;
   }
@@ -74,8 +76,14 @@ sub _read_pid {
 sub _run_script_command {
   my ($self, $command) = @_;
 
-  my $exe = catfile(catdir(SL::System::Process->exe_dir, 'scripts'), 'task_server.pl');
-  $self->last_command_output(`${exe} ${command}`);
+  my ($fh, $file_name) = tempfile();
+  my $exe              = catfile(catdir(SL::System::Process->exe_dir, 'scripts'), 'task_server.pl');
+
+  system "${exe} ${command} >> ${file_name} 2>&1";
+
+  $fh->close;
+
+  $self->last_command_output(read_file($file_name));
 
   return $? == 0 ? 1 : undef;
 }