line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Supervisord::Client; |
2
|
|
|
|
|
|
|
$Supervisord::Client::VERSION = '0.22'; |
3
|
1
|
|
|
1
|
|
15649
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
502
|
use LWP::Protocol::http::SocketUnixAlt; |
|
1
|
|
|
|
|
77830
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
1056
|
use RPC::XML::Client qw[ $RPC::XML::ERROR ]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Moo::Lax; |
8
|
|
|
|
|
|
|
use Carp; |
9
|
|
|
|
|
|
|
use Safe::Isa; |
10
|
|
|
|
|
|
|
use Config::INI::Reader; |
11
|
|
|
|
|
|
|
use URI; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
LWP::Protocol::implementor( |
14
|
|
|
|
|
|
|
supervisorsocketunix => 'LWP::Protocol::http::SocketUnixAlt' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has path_to_supervisor_config => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
required => 0, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has serverurl => ( |
22
|
|
|
|
|
|
|
is => 'lazy', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has rpc => ( |
26
|
|
|
|
|
|
|
is => 'lazy', |
27
|
|
|
|
|
|
|
handles => { ua => 'useragent' }, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has username => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
required => 0, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has password => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
required => 0, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _build_serverurl { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
my $hash = |
44
|
|
|
|
|
|
|
Config::INI::Reader->read_file( $self->path_to_supervisor_config ); |
45
|
|
|
|
|
|
|
return $hash->{supervisorctl}{serverurl} |
46
|
|
|
|
|
|
|
|| croak "couldnt find serverurl in supervisorctl section of " |
47
|
|
|
|
|
|
|
. $self->path_to_supervisor_config; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _build_rpc { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
my $url = $self->serverurl; |
53
|
|
|
|
|
|
|
my $uri = URI->new( $url ); |
54
|
|
|
|
|
|
|
if( lc($uri->scheme) eq 'unix' ) { |
55
|
|
|
|
|
|
|
my $socket_uri = URI->new("supervisorsocketunix:"); |
56
|
|
|
|
|
|
|
$socket_uri->path_segments( $uri->path_segments, "", "RPC2" ); |
57
|
|
|
|
|
|
|
$uri = $socket_uri; |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
$uri->path_segments( $uri->path_segments, "RPC2" ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
my $cli = |
62
|
|
|
|
|
|
|
RPC::XML::Client->new( $uri, error_handler => sub { confess @_ } ); |
63
|
|
|
|
|
|
|
my $ua = $cli->useragent; |
64
|
|
|
|
|
|
|
if( $self->username ) { |
65
|
|
|
|
|
|
|
$ua->credentials( $uri->host_port, 'default', $self->username, $self->password ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
return $cli; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub BUILD { |
71
|
|
|
|
|
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
$self->path_to_supervisor_config |
73
|
|
|
|
|
|
|
|| $self->serverurl |
74
|
|
|
|
|
|
|
|| croak "path_to_supervisor_config or serverurl required."; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
our $AUTOLOAD; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub AUTOLOAD { |
80
|
|
|
|
|
|
|
my $remote_method = $AUTOLOAD; |
81
|
|
|
|
|
|
|
$remote_method =~ s/.*:://; |
82
|
|
|
|
|
|
|
my ( $self, @args ) = @_; |
83
|
|
|
|
|
|
|
$self->send_rpc_request("supervisor.$remote_method", @args ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
sub send_rpc_request { |
86
|
|
|
|
|
|
|
my( $self, @params ) = @_; |
87
|
|
|
|
|
|
|
my $ret = $self->rpc->send_request( @params ); |
88
|
|
|
|
|
|
|
return $ret->value if $ret->$_can("value"); |
89
|
|
|
|
|
|
|
return $ret; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Supervisord::Client - a perl client for Supervisord's XMLRPC. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SYNOPSIS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $client = Supervisord::Client->new( serverurl => "unix:///tmp/socky.sock" ); |
101
|
|
|
|
|
|
|
#or |
102
|
|
|
|
|
|
|
my $client = Supervisord::Client->new( serverurl => "http://foo.bar:25123" ); |
103
|
|
|
|
|
|
|
#or |
104
|
|
|
|
|
|
|
my $client = Supervisord::Client->new( path_to_supervisor_config => "/etc/supervisor/supervisor.conf" ); |
105
|
|
|
|
|
|
|
warn $_->{description} for(@{ $client->getAllProcessInfo }); |
106
|
|
|
|
|
|
|
#or |
107
|
|
|
|
|
|
|
warn $_->{description} for(@{ $client->send_rpc_request("supervisor.getAllProcessInfo") }); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 DESCRIPTION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This module is for people who are using supervisord ( L ) to manage their daemons, |
112
|
|
|
|
|
|
|
and ran into problems with the http over Unix socket part. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
See L for the API docs of what the supervisord XMLRPC supports. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 new |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Constructor, provided by Moo. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 rpc |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Access to the RPC::XML::Client object. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 ua |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Access to the LWP::UserAgent object from the RPC::XML::Client |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 send_rpc_request( remote_method, @params ) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 AUTOLOAD |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This module uses AUTOLOAD to proxy calls to send_rpc_request. See synopsis for examples. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 CONSTRUCTOR PARAMETERS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
path_to_supervisor_config or serverurl is required. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item path_to_supervisor_config |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
optional - ex: /tmp/super.sock |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item serverurl |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
optional - in supervisor format, ex: unix:///tmp.super.sock | http://myserver.local:8080 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=back |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 LICENSE |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This library is free software and may be distributed under the same terms as perl itself. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 AUTHOR |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Samuel Kaufman L |
162
|
|
|
|
|
|
|
|