… | |
… | |
37 | |
37 | |
38 | # node configuration: services |
38 | # node configuration: services |
39 | aemp setservices initfunc... # set service functions |
39 | aemp setservices initfunc... # set service functions |
40 | aemp addservice <initfunc> # add an instance of a service |
40 | aemp addservice <initfunc> # add an instance of a service |
41 | aemp delservice <initfunc> # delete one instance of a service |
41 | aemp delservice <initfunc> # delete one instance of a service |
|
|
42 | |
|
|
43 | # profile-specific configuration |
|
|
44 | aemp profile <name> <command>... # apply command to profile only |
|
|
45 | aemp delprofile <name> # eradicate the named profile |
42 | |
46 | |
43 | =head1 DESCRIPTION |
47 | =head1 DESCRIPTION |
44 | |
48 | |
45 | With aemp you can configure various aspects of AnyEvent::MP and its |
49 | With aemp you can configure various aspects of AnyEvent::MP and its |
46 | protocol. |
50 | protocol. |
… | |
… | |
98 | "2>", "/dev/null"; |
102 | "2>", "/dev/null"; |
99 | |
103 | |
100 | "$cert$key" |
104 | "$cert$key" |
101 | } |
105 | } |
102 | |
106 | |
103 | our $cfg = \%AnyEvent::MP::Config::CFG; |
107 | our $cfg = AnyEvent::MP::Config::config; |
104 | our $profile = $cfg; |
108 | our $profile = $cfg; |
105 | |
109 | |
106 | sub resolve_port { |
110 | sub resolve_port { |
107 | my ($node, $port) = split /#/, $_[0], 2; |
111 | my ($node, $port) = split /#/, $_[0], 2; |
108 | |
112 | |
109 | $node = (resolve_node $node)->recv; |
113 | $node = (resolve_node $node)->recv; |
110 | "$node#$port" |
114 | "$node#$port" |
111 | } |
115 | } |
|
|
116 | |
|
|
117 | sub docmd; |
112 | |
118 | |
113 | our %CMD = ( |
119 | our %CMD = ( |
114 | snd => sub { |
120 | snd => sub { |
115 | my $port = resolve_port shift @ARGV; |
121 | my $port = resolve_port shift @ARGV; |
116 | initialise_node "slave/", node_of $port; |
122 | initialise_node "slave/", node_of $port; |
… | |
… | |
199 | $profile->{seeds} = [@ARGV]; |
205 | $profile->{seeds} = [@ARGV]; |
200 | @ARGV = (); |
206 | @ARGV = (); |
201 | ++$cfg->{dirty}; |
207 | ++$cfg->{dirty}; |
202 | }, |
208 | }, |
203 | addseed => sub { |
209 | addseed => sub { |
|
|
210 | @ARGV >= 1 |
|
|
211 | or die "seed noderef missing\n"; |
204 | my $seed = shift @ARGV; |
212 | my $seed = shift @ARGV; |
|
|
213 | |
205 | @{ $profile->{seeds} } = grep $_ ne $seed, @{ $profile->{seeds} }; |
214 | @{ $profile->{seeds} } = grep $_ ne $seed, @{ $profile->{seeds} }; |
206 | push @{ $profile->{seeds} }, $seed; |
215 | push @{ $profile->{seeds} }, $seed; |
207 | ++$cfg->{dirty}; |
216 | ++$cfg->{dirty}; |
208 | }, |
217 | }, |
209 | delseed => sub { |
218 | delseed => sub { |
|
|
219 | @ARGV >= 1 |
|
|
220 | or die "seed noderef missing\n"; |
210 | my $seed = shift @ARGV; |
221 | my $seed = shift @ARGV; |
|
|
222 | |
211 | @{ $profile->{seeds} } = grep $_ ne $seed, @{ $profile->{seeds} }; |
223 | @{ $profile->{seeds} } = grep $_ ne $seed, @{ $profile->{seeds} }; |
212 | ++$cfg->{dirty}; |
224 | ++$cfg->{dirty}; |
213 | }, |
225 | }, |
214 | |
226 | |
215 | setservices => sub { |
227 | setservices => sub { |
216 | $profile->{services} = [@ARGV]; |
228 | $profile->{services} = [@ARGV]; |
217 | @ARGV = (); |
229 | @ARGV = (); |
218 | ++$cfg->{dirty}; |
230 | ++$cfg->{dirty}; |
219 | }, |
231 | }, |
220 | addservice => sub { |
232 | addservice => sub { |
|
|
233 | @ARGV >= 1 |
|
|
234 | or die "service specification missing\n"; |
221 | my $service = shift @ARGV; |
235 | my $service = shift @ARGV; |
222 | push @{ $profile->{services} }, $service; |
236 | push @{ $profile->{services} }, $service; |
223 | ++$cfg->{dirty}; |
237 | ++$cfg->{dirty}; |
224 | }, |
238 | }, |
225 | delservice => sub { |
239 | delservice => sub { |
|
|
240 | @ARGV >= 1 |
|
|
241 | or die "service specification missing\n"; |
226 | my $service = shift @ARGV; |
242 | my $service = shift @ARGV; |
227 | for (0 .. $#{ $profile->{services} }) { |
243 | for (0 .. $#{ $profile->{services} }) { |
228 | next unless $profile->{services}[$_] eq $service; |
244 | next unless $profile->{services}[$_] eq $service; |
229 | splice @{ $profile->{services} }, $_, 1; |
245 | splice @{ $profile->{services} }, $_, 1; |
230 | last; |
246 | last; |
231 | } |
247 | } |
232 | ++$cfg->{dirty}; |
248 | ++$cfg->{dirty}; |
233 | }, |
249 | }, |
|
|
250 | |
|
|
251 | profile => sub { |
|
|
252 | @ARGV >= 2 |
|
|
253 | or die "profile name or subcommand are missing\n"; |
|
|
254 | my $name = shift @ARGV; |
|
|
255 | |
|
|
256 | $profile = $cfg->{profile}{$name} ||= {}; |
|
|
257 | |
|
|
258 | docmd; |
|
|
259 | }, |
|
|
260 | delprofile => sub { |
|
|
261 | @ARGV >= 1 |
|
|
262 | or die "profile name is missing\n"; |
|
|
263 | my $name = shift @ARGV; |
|
|
264 | |
|
|
265 | delete $cfg->{profile}{$name}; |
|
|
266 | }, |
234 | ); |
267 | ); |
235 | |
268 | |
236 | sub docmd { |
269 | sub docmd { |
237 | my $cmd = shift @ARGV; |
270 | my $cmd = shift @ARGV; |
238 | |
271 | |