1 package SL::System::TaskServer;
5 use parent qw(Rose::Object);
7 use Rose::Object::MakeMethods::Generic (
8 scalar => [ qw(last_command_output) ],
12 use File::Spec::Functions qw(:ALL);
14 use SL::System::Process;
25 my $pid = $self->_read_pid;
26 return ERR_PID_FILE unless $pid;
28 return kill(0, $pid) ? OK : ERR_PROCESS;
34 return $self->status == OK;
40 return $self->_run_script_command('start');
46 return $self->_run_script_command('stop');
52 my $pid = $self->_read_pid;
53 return undef unless $pid;
54 return kill('ALRM', $pid) ? 1 : undef;
64 my $exe_dir = SL::System::Process->exe_dir;
66 foreach my $conf (qw(kivitendo.conf lx_office.conf kivitendo.conf.default)) {
67 my $pid_file_name = join '.', splitdir($exe_dir), "config.${conf}.pid";
68 my $pid_file_path = catfile(catdir($exe_dir, 'users', 'pid'), $pid_file_name);
70 return join('', read_file($pid_file_path)) * 1 if -f $pid_file_path;
74 sub _run_script_command {
75 my ($self, $command) = @_;
77 my $exe = catfile(catdir(SL::System::Process->exe_dir, 'scripts'), 'task_server.pl');
78 $self->last_command_output(`${exe} ${command}`);
80 return $? == 0 ? 1 : undef;
92 SL::System::TaskServer - programmatic interface to the external task server component
97 my $task_server = SL->TaskServer->new;
99 # Start the server if it is not running
100 if (!$task_server->is_running) {
104 # Stop it if it is running
105 if ($task_server->is_running) {
115 Returns C<trueish> if the server is running. This is done by using
116 Perl's C<kill> function with a "signal" of C<0> for the process ID
117 which in turn is read from the daemon's PID file.
119 If the PID file is not found or if C<kill> returns a non-successful
120 value then a C<falsish> value is returned.
122 =item C<last_command_output>
124 Returns the output of the last C<system> command executed, e.g. from a
125 call to L<start> or L<stop>.
129 Starts the task server. Does not check whether or not it is running,
130 neither before not after trying to start it.
132 Returns C<1> if the system command C<./scripts/task_server.pl start>
133 exits with an exit code of C<0> and C<undef> otherwise.
135 The command's output can be queried with L<last_command_output>.
139 Queries the task server status. Returns one of these values:
145 C<OK> or C<0>: the task server is running and signals can be sent to
150 C<ERR_PID_FILE> or C<-1>: the PID file could not be found or read
154 C<ERR_PROCESS> or C<-2>: the PID file could was found and read, but
155 it's not possible to send signals to the process, e.g. because it is
156 not running or owned by a different user ID.
162 Stops the task server. Does not check whether or not it is running,
163 neither before not after trying to start it.
165 Returns C<1> if the system command C<./scripts/task_server.pl stop>
166 exits with an exit code of C<0> and C<undef> otherwise.
168 The command's output can be queried with L<last_command_output>.
172 Sends a signal to the task server process causing it to wake up and
173 process its job queue immediately.
175 Returns C<1> if the signal could be sent and C<undef> otherwise.
185 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>