line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::EventStreamr::Roles::ProcessControl; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
150679
|
use v5.010; |
|
3
|
|
|
|
|
10
|
|
4
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
57
|
|
5
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
76
|
|
6
|
3
|
|
|
3
|
|
15
|
use Method::Signatures 20140224; # libmethod-signatures-perl |
|
3
|
|
|
|
|
66
|
|
|
3
|
|
|
|
|
20
|
|
7
|
3
|
|
|
3
|
|
3108
|
use Proc::Daemon; # libproc-daemon-perl |
|
3
|
|
|
|
|
28109
|
|
|
3
|
|
|
|
|
82
|
|
8
|
3
|
|
|
3
|
|
1818
|
use Proc::ProcessTable; # libproc-processtable-perl |
|
3
|
|
|
|
|
15322
|
|
|
3
|
|
|
|
|
127
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
42
|
use Moo::Role; # libmoo-perl |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
26
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: A process role |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.5'; # VERSION: Generated by DZP::OurPkg:Version |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
requires 'cmd','id'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'pid' => ( is => 'rw', lazy => 1, builder => 1, clearer => 'clear_pid' ); |
20
|
|
|
|
|
|
|
|
21
|
3
|
50
|
|
3
|
|
3302
|
method _build_pid() { |
|
8
|
|
|
8
|
|
2024136
|
|
|
8
|
|
|
|
|
80
|
|
22
|
8
|
|
|
|
|
310
|
my $pt = Proc::ProcessTable->new; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Sometimes our processes report a different command than |
25
|
|
|
|
|
|
|
# how they were started. Also they often spawn a new detached |
26
|
|
|
|
|
|
|
# process, so we can't grab the pid from Proc::Daemon::Init. |
27
|
8
|
100
|
|
|
|
29117
|
my $regex = $self->cmd_regex ? $self->cmd_regex : $self->cmd; |
28
|
8
|
|
|
|
|
26
|
my @procs = grep { $_->cmndline =~ /$regex/ } @{ $pt->table }; |
|
90
|
|
|
|
|
2333
|
|
|
8
|
|
|
|
|
25322
|
|
29
|
|
|
|
|
|
|
|
30
|
8
|
100
|
|
|
|
185
|
if (@procs) { |
31
|
3
|
|
|
|
|
54
|
$self->info("Process ".$self->id." found with pid=".$procs[0]->pid); |
32
|
3
|
|
|
|
|
35
|
return $procs[0]->pid; |
33
|
|
|
|
|
|
|
} else { |
34
|
5
|
|
|
|
|
367
|
return 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
3
|
50
|
|
3
|
|
2092
|
method start() { |
|
4
|
|
|
4
|
|
12889
|
|
|
4
|
|
|
|
|
23
|
|
40
|
4
|
|
|
|
|
29
|
my %proc_opts = ( exec_command => $self->cmd ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Proc::Daemon will exit parent when started in Void |
43
|
4
|
|
|
|
|
57
|
my $state = Proc::Daemon::Init( \%proc_opts ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
3
|
50
|
|
3
|
|
1762
|
method stop() { |
|
4
|
|
|
4
|
|
2910
|
|
|
4
|
|
|
|
|
28
|
|
48
|
4
|
100
|
|
|
|
52
|
if ($self->pid) { |
49
|
3
|
|
|
|
|
134
|
kill 9, $self->pid; |
50
|
3
|
|
|
|
|
279
|
$self->clear_pid; |
51
|
3
|
|
|
|
|
741
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
1
|
|
|
|
|
5
|
return 0; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
3
|
50
|
|
3
|
|
1698
|
method running() { |
|
5
|
|
|
5
|
|
1008811
|
|
|
5
|
|
|
|
|
100
|
|
58
|
|
|
|
|
|
|
#TODO: pid 0 returns true. Should rework the logic here. |
59
|
5
|
100
|
|
|
|
115
|
if ( ! $self->pid ) { |
|
|
50
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} elsif ( kill 0, $self->pid ) { |
62
|
2
|
|
|
|
|
398
|
return 1; |
63
|
|
|
|
|
|
|
} |
64
|
3
|
|
|
|
|
194
|
$self->clear_pid; |
65
|
3
|
|
|
|
|
1416
|
return 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
with('App::EventStreamr::Roles::Logger'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=encoding UTF-8 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
App::EventStreamr::Roles::ProcessControl - A process role |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 0.5 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This is a role that provides 'start', 'stop' and 'running' methods. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This is a Role that can be consumed to provide process operations |
93
|
|
|
|
|
|
|
used throughout EventStreamr. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
It requires a 'cmd' attribute and will utilise an optional |
96
|
|
|
|
|
|
|
'cmd_regex' if one exists. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 METHODS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 start |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$proc->start; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Forks the command and returns. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 stop |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$proc->stop; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Stops the running process if it is found. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 running |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$proc->running; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns 1 if running, 0 if not. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Leon Wright < techman@cpan.org > |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Leon Wright. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software, licensed under: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The GNU Affero General Public License, Version 3, November 2007 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |