line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Driver::Console::Client; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1891
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use POE qw(Wheel::ReadLine); |
5
|
|
|
|
|
|
|
use Net::Telnet; |
6
|
|
|
|
|
|
|
with qw(MooseX::Getopt); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Gearman::Driver::Console::Client - Console client with readline |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
If you got many worker servers and want to change processes at once |
15
|
|
|
|
|
|
|
on all servers while runtime, this tool comes in handy: |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
usage: gearman_driver_console.pl [long options...] |
18
|
|
|
|
|
|
|
--server A list of servers to connect to: "host1 host2 host3:47301 host4:47302" |
19
|
|
|
|
|
|
|
--history Readline history, defaults to $HOME/.gearman_driver_history |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$ ~/Gearman-Driver$ gearman_driver.pl --console_port 47301 & |
22
|
|
|
|
|
|
|
[1] 89053 |
23
|
|
|
|
|
|
|
$ ~/Gearman-Driver$ gearman_driver.pl --console_port 47302 & |
24
|
|
|
|
|
|
|
[2] 89066 |
25
|
|
|
|
|
|
|
$ ~/Gearman-Driver$ gearman_driver.pl --console_port 47303 & |
26
|
|
|
|
|
|
|
[3] 89079 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$ ~/Gearman-Driver$ gearman_driver_console.pl --server "localhost:47301 localhost:47302 localhost:47303" |
29
|
|
|
|
|
|
|
console> status |
30
|
|
|
|
|
|
|
localhost:47301> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
31
|
|
|
|
|
|
|
localhost:47301> GDExamples::Convert::convert_to_gif 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
32
|
|
|
|
|
|
|
localhost:47301> . |
33
|
|
|
|
|
|
|
localhost:47302> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
34
|
|
|
|
|
|
|
localhost:47302> GDExamples::Convert::convert_to_gif 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
35
|
|
|
|
|
|
|
localhost:47302> . |
36
|
|
|
|
|
|
|
localhost:47303> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
37
|
|
|
|
|
|
|
localhost:47303> GDExamples::Convert::convert_to_gif 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
38
|
|
|
|
|
|
|
localhost:47303> . |
39
|
|
|
|
|
|
|
console> show GDExamples::Convert::convert_to_jpeg |
40
|
|
|
|
|
|
|
localhost:47301> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
41
|
|
|
|
|
|
|
localhost:47301> 89061 |
42
|
|
|
|
|
|
|
localhost:47301> 89063 |
43
|
|
|
|
|
|
|
localhost:47301> 89062 |
44
|
|
|
|
|
|
|
localhost:47301> . |
45
|
|
|
|
|
|
|
localhost:47302> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
46
|
|
|
|
|
|
|
localhost:47302> 89074 |
47
|
|
|
|
|
|
|
localhost:47302> 89075 |
48
|
|
|
|
|
|
|
localhost:47302> 89076 |
49
|
|
|
|
|
|
|
localhost:47302> . |
50
|
|
|
|
|
|
|
localhost:47303> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
51
|
|
|
|
|
|
|
localhost:47303> 89088 |
52
|
|
|
|
|
|
|
localhost:47303> 89089 |
53
|
|
|
|
|
|
|
localhost:47303> 89087 |
54
|
|
|
|
|
|
|
localhost:47303> . |
55
|
|
|
|
|
|
|
console> shutdown |
56
|
|
|
|
|
|
|
[1] Done gearman_driver.pl --console_port 47301 |
57
|
|
|
|
|
|
|
[2]- Done gearman_driver.pl --console_port 47302 |
58
|
|
|
|
|
|
|
[3]+ Done gearman_driver.pl --console_port 47303 |
59
|
|
|
|
|
|
|
$ ~/Gearman-Driver$ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has 'server' => ( |
64
|
|
|
|
|
|
|
documentation => 'A list of servers to connect to: "host1 host2 host3:47301 host4:47302"', |
65
|
|
|
|
|
|
|
is => 'rw', |
66
|
|
|
|
|
|
|
isa => 'Str', |
67
|
|
|
|
|
|
|
required => 1, |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has 'telnet' => ( |
71
|
|
|
|
|
|
|
default => sub { {} }, |
72
|
|
|
|
|
|
|
handles => { |
73
|
|
|
|
|
|
|
add_telnet => 'set', |
74
|
|
|
|
|
|
|
get_telnet => 'get', |
75
|
|
|
|
|
|
|
servers => 'keys', |
76
|
|
|
|
|
|
|
}, |
77
|
|
|
|
|
|
|
is => 'ro', |
78
|
|
|
|
|
|
|
isa => 'HashRef', |
79
|
|
|
|
|
|
|
traits => [qw(NoGetopt Hash)], |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
has 'history' => ( |
83
|
|
|
|
|
|
|
default => "$ENV{HOME}/.gearman_driver_history", |
84
|
|
|
|
|
|
|
documentation => 'Readline history, defaults to $HOME/.gearman_driver_history', |
85
|
|
|
|
|
|
|
is => 'rw', |
86
|
|
|
|
|
|
|
isa => 'Str', |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has 'session' => ( |
90
|
|
|
|
|
|
|
is => 'ro', |
91
|
|
|
|
|
|
|
isa => 'POE::Session', |
92
|
|
|
|
|
|
|
traits => [qw(NoGetopt)], |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub run { |
96
|
|
|
|
|
|
|
my ($self) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
foreach my $server ( split /\s+/, $self->server ) { |
99
|
|
|
|
|
|
|
my ( $host, $port ) = split /:/, $server; |
100
|
|
|
|
|
|
|
$port ||= 47300; |
101
|
|
|
|
|
|
|
my $telnet = Net::Telnet->new( |
102
|
|
|
|
|
|
|
host => $host, |
103
|
|
|
|
|
|
|
port => $port, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
$telnet->open; |
106
|
|
|
|
|
|
|
$self->add_telnet( $server => $telnet ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$self->{session} = POE::Session->create( |
110
|
|
|
|
|
|
|
object_states => [ |
111
|
|
|
|
|
|
|
$self => { |
112
|
|
|
|
|
|
|
_start => '_start', |
113
|
|
|
|
|
|
|
got_user_input => '_handle_user_input', |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
] |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
POE::Kernel->run(); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _handle_user_input { |
122
|
|
|
|
|
|
|
my ( $self, $input, $exception ) = @_[ OBJECT, ARG0, ARG1 ]; |
123
|
|
|
|
|
|
|
my $console = $_[HEAP]{console}; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
unless ( defined $input ) { |
126
|
|
|
|
|
|
|
$console->put("$exception caught. B'bye!"); |
127
|
|
|
|
|
|
|
$_[KERNEL]->signal( $_[KERNEL], "UIDESTROY" ); |
128
|
|
|
|
|
|
|
$console->write_history( $self->history ); |
129
|
|
|
|
|
|
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$console->addhistory($input); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my ( $command, $pipe ) = split /\|/, $input; |
135
|
|
|
|
|
|
|
my @lines = (); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
foreach my $server ( sort $self->servers ) { |
138
|
|
|
|
|
|
|
my $telnet = $self->get_telnet($server); |
139
|
|
|
|
|
|
|
$telnet->print($command); |
140
|
|
|
|
|
|
|
while ( my $line = $telnet->getline() ) { |
141
|
|
|
|
|
|
|
if ($pipe) { |
142
|
|
|
|
|
|
|
push @lines, "$server> $line"; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
else { |
145
|
|
|
|
|
|
|
print "$server> $line"; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
last if $line eq ".\n"; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
if ($pipe) { |
152
|
|
|
|
|
|
|
open CMD, "|$pipe"; |
153
|
|
|
|
|
|
|
print CMD $_ foreach @lines; |
154
|
|
|
|
|
|
|
close CMD; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
if ( $input eq 'quit' || $input eq 'shutdown' ) { |
158
|
|
|
|
|
|
|
$console->write_history( $self->history ); |
159
|
|
|
|
|
|
|
$_[KERNEL]->signal( $_[KERNEL], "UIDESTROY" ); |
160
|
|
|
|
|
|
|
return; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$console->get("console> "); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub _start { |
167
|
|
|
|
|
|
|
$_[HEAP]{console} = POE::Wheel::ReadLine->new( InputEvent => 'got_user_input' ); |
168
|
|
|
|
|
|
|
$_[HEAP]{console}->read_history( $_[OBJECT]->history ); |
169
|
|
|
|
|
|
|
$_[HEAP]{console}->get("console> "); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
See L<Gearman::Driver>. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
See L<Gearman::Driver>. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 SEE ALSO |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over 4 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * L<Gearman::Driver> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Adaptor> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Console> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Console::Basic> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Job> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Job::Method> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Loader> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Observer> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Worker> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Worker::Base> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |