… | |
… | |
51 | aemp delservice <initfunc> # delete one instance of a service |
51 | aemp delservice <initfunc> # delete one instance of a service |
52 | |
52 | |
53 | # profile-specific configuration |
53 | # profile-specific configuration |
54 | aemp profile <name> <command>... # apply command to profile only |
54 | aemp profile <name> <command>... # apply command to profile only |
55 | aemp parent <name> # specify a parent profile |
55 | aemp parent <name> # specify a parent profile |
|
|
56 | aemp delparent # clear parent again |
56 | aemp delprofile <name> # eradicate the named profile |
57 | aemp delprofile <name> # eradicate the named profile |
57 | aemp showprofile <name> # display given profile |
58 | aemp showprofile <name> # display given profile |
58 | aemp showconfig <name> # display effective config |
59 | aemp showconfig <name> ... # display effective config |
59 | |
60 | |
60 | =head1 DESCRIPTION |
61 | =head1 DESCRIPTION |
61 | |
62 | |
62 | With aemp you can configure various aspects of AnyEvent::MP and its |
63 | With aemp you can configure various aspects of AnyEvent::MP and its |
63 | protocol, send various messages and even run a node. |
64 | protocol, send various messages and even run a node. |
… | |
… | |
94 | =back |
95 | =back |
95 | |
96 | |
96 | =head2 PROTOCOL COMMANDS |
97 | =head2 PROTOCOL COMMANDS |
97 | |
98 | |
98 | These commands actually communicate with other nodes. They all use a node |
99 | These commands actually communicate with other nodes. They all use a node |
99 | profile name of L<anon/> currently. |
100 | profile name of C<aemp> (specifying a dfeault node ID of C<anon/> and a |
|
|
101 | binds list containing C<*:*> only). |
100 | |
102 | |
101 | They all use a timeout of five seconds, after which they give up. |
103 | They all use a timeout of five seconds, after which they give up. |
102 | |
104 | |
103 | =over 4 |
105 | =over 4 |
104 | |
106 | |
… | |
… | |
252 | |
254 | |
253 | Sets the list of bind addresses explicitly - see the F<aemp setseeds> |
255 | Sets the list of bind addresses explicitly - see the F<aemp setseeds> |
254 | command for the exact syntax. In addition, a value of C<0> for the port |
256 | command for the exact syntax. In addition, a value of C<0> for the port |
255 | means to use a dynamically-assigned port. |
257 | means to use a dynamically-assigned port. |
256 | |
258 | |
257 | Note that the C<*>, C<*:0> or C<*:port> values are very useful here. |
259 | Note that the C<*>, C<*:*> or C<*:port> values are very useful here. |
258 | |
260 | |
259 | Example: bind on the default port (4040) on all local interfaces. |
261 | Example: bind on the default port (4040) on all local interfaces. |
260 | |
262 | |
261 | aemp setbinds "*" |
263 | aemp setbinds "*" |
262 | |
264 | |
263 | Example: bind on a random port on all local interfaces. |
265 | Example: bind on a random port on all local interfaces. |
264 | |
266 | |
265 | aemp setbinds "*:0" |
267 | aemp setbinds "*:*" |
266 | |
268 | |
267 | Example: resolve "doomed.mydomain" and try to bind on port C<4040> of all |
269 | Example: resolve "doomed.mydomain" and try to bind on port C<4040> of all |
268 | IP addressess returned. |
270 | IP addressess returned. |
269 | |
271 | |
270 | aep setbinds doomed.mydomain |
272 | aep setbinds doomed.mydomain |
… | |
… | |
334 | |
336 | |
335 | Example: create a C<server> profile, give it a random node name, some seed |
337 | Example: create a C<server> profile, give it a random node name, some seed |
336 | nodes and bind it on an unspecified port on all local interfaces. You |
338 | nodes and bind it on an unspecified port on all local interfaces. You |
337 | should add some services then and run the node... |
339 | should add some services then and run the node... |
338 | |
340 | |
339 | aemp server setnodeid anon/ setseeds doomed,10.0.0.2:5000 setbinds "*:0" |
341 | aemp server setnodeid anon/ setseeds doomed,10.0.0.2:5000 setbinds "*:*" |
340 | |
342 | |
341 | =item delprofile <name> |
343 | =item delprofile <name> |
342 | |
344 | |
343 | Deletes the profile of the given name. |
345 | Deletes the profile of the given name. |
344 | |
346 | |
… | |
… | |
365 | =item showprofile <name> |
367 | =item showprofile <name> |
366 | |
368 | |
367 | Shows the values of the given profile, and only those, no inherited |
369 | Shows the values of the given profile, and only those, no inherited |
368 | values. |
370 | values. |
369 | |
371 | |
370 | =item showconfig <name> |
372 | =item showconfig <name> <key value...> |
371 | |
373 | |
372 | Shows the I<effective> config, i.e. the values as used by a node started |
374 | Shows the I<effective> config, i.e. the values as used by a node started |
373 | with the given profile name. |
375 | with the given profile name. Any additional key-value pairs specified |
|
|
376 | augment the configuration, just as with C<initialise_node>. |
374 | |
377 | |
375 | If the name is omitted, show the global default config. |
378 | If all arguments are omitted, show the global default config. |
376 | |
379 | |
377 | =back |
380 | =back |
378 | |
381 | |
379 | =cut |
382 | =cut |
380 | |
383 | |
… | |
… | |
392 | |
395 | |
393 | AnyEvent::Watchdog::autorestart (1); |
396 | AnyEvent::Watchdog::autorestart (1); |
394 | AnyEvent::Watchdog::heartbeat (300); |
397 | AnyEvent::Watchdog::heartbeat (300); |
395 | |
398 | |
396 | require AnyEvent; |
399 | require AnyEvent; |
397 | require AnyEvent::MP; |
400 | require AnyEvent::MP::Kernel; |
398 | AnyEvent::MP::initialise_node (@ARGV); |
401 | AnyEvent::MP::Kernel::initialise_node (@ARGV); |
399 | |
402 | |
400 | AnyEvent::detect () eq "AnyEvent::Impl::EV" |
403 | AnyEvent::detect () eq "AnyEvent::Impl::EV" |
401 | ? EV::loop () |
404 | ? EV::loop () |
402 | : AE::cv ()->recv; |
405 | : AE::cv ()->recv; |
403 | } |
406 | } |
… | |
… | |
435 | "2>", "/dev/null"; |
438 | "2>", "/dev/null"; |
436 | |
439 | |
437 | "$cert$key" |
440 | "$cert$key" |
438 | } |
441 | } |
439 | |
442 | |
|
|
443 | sub init { |
|
|
444 | initialise_node aemp => nodeid => "anon/", binds => ["*:*"]; |
|
|
445 | } |
|
|
446 | |
440 | our $cfg = AnyEvent::MP::Config::config; |
447 | our $cfg = AnyEvent::MP::Config::config; |
441 | our $profile = $cfg; |
448 | our $profile = $cfg; |
442 | |
449 | |
443 | sub trace { |
450 | sub trace { |
444 | my ($node) = @_; |
451 | my ($node) = @_; |
… | |
… | |
448 | my $to = AE::timer 15, 0, sub { |
455 | my $to = AE::timer 15, 0, sub { |
449 | warn "timeout\n"; |
456 | warn "timeout\n"; |
450 | $cv->(); |
457 | $cv->(); |
451 | }; |
458 | }; |
452 | |
459 | |
453 | initialise_node "anon/"; |
460 | init; |
454 | |
461 | |
455 | my $reply = port { |
462 | my $reply = port { |
456 | my ($node, @neigh) = @_; |
463 | my ($node, @neigh) = @_; |
457 | |
464 | |
458 | @neigh = grep $_ ne $NODE, @neigh; |
465 | @neigh = grep $_ ne $NODE, @neigh; |
… | |
… | |
478 | sub docmd; |
485 | sub docmd; |
479 | |
486 | |
480 | our %CMD = ( |
487 | our %CMD = ( |
481 | snd => sub { |
488 | snd => sub { |
482 | my $port = shift @ARGV; |
489 | my $port = shift @ARGV; |
483 | initialise_node "anon/"; |
490 | init; |
484 | |
491 | |
485 | snd $port, @ARGV; @ARGV = (); |
492 | snd $port, @ARGV; @ARGV = (); |
486 | |
493 | |
487 | my $cv = AE::cv; |
494 | my $cv = AE::cv; |
488 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
495 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
… | |
… | |
493 | print join " ", $cv->recv, "\n"; |
500 | print join " ", $cv->recv, "\n"; |
494 | }, |
501 | }, |
495 | |
502 | |
496 | rpc => sub { |
503 | rpc => sub { |
497 | my $port = shift @ARGV; |
504 | my $port = shift @ARGV; |
498 | initialise_node "anon/"; |
505 | init; |
499 | |
506 | |
500 | my $cv = AE::cv; |
507 | my $cv = AE::cv; |
501 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
508 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
502 | snd $port, @ARGV, port { &$cv }; @ARGV = (); |
509 | snd $port, @ARGV, port { &$cv }; @ARGV = (); |
503 | mon $port, $cv; |
510 | mon $port, $cv; |
… | |
… | |
505 | print +(substr JSON::XS->new->encode ([$cv->recv]), 1, -1), "\n"; |
512 | print +(substr JSON::XS->new->encode ([$cv->recv]), 1, -1), "\n"; |
506 | }, |
513 | }, |
507 | |
514 | |
508 | mon => sub { |
515 | mon => sub { |
509 | my $port = shift @ARGV; |
516 | my $port = shift @ARGV; |
510 | initialise_node "anon/"; |
517 | init; |
511 | |
518 | |
512 | mon $port, my $cv = AE::cv; |
519 | mon $port, my $cv = AE::cv; |
513 | print join " ", $cv->recv, "\n"; |
520 | print join " ", $cv->recv, "\n"; |
514 | }, |
521 | }, |
515 | |
522 | |
516 | eval => sub { |
523 | eval => sub { |
517 | my $node = node_of shift @ARGV; |
524 | my $node = node_of shift @ARGV; |
518 | my $expr = join " ", @ARGV; @ARGV = (); |
525 | my $expr = join " ", @ARGV; @ARGV = (); |
519 | initialise_node "anon/"; |
526 | init; |
520 | |
527 | |
521 | my $cv = AE::cv; |
528 | my $cv = AE::cv; |
522 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
529 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
523 | AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv }; |
530 | AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv }; |
524 | mon $node, $cv; |
531 | mon $node, $cv; |
… | |
… | |
705 | print JSON::XS->new->pretty->encode ($cfg->{profile}{$name} || {}); |
712 | print JSON::XS->new->pretty->encode ($cfg->{profile}{$name} || {}); |
706 | }, |
713 | }, |
707 | showconfig => sub { |
714 | showconfig => sub { |
708 | my $name = @ARGV ? shift @ARGV : AnyEvent::MP::Kernel::_nodename; |
715 | my $name = @ARGV ? shift @ARGV : AnyEvent::MP::Kernel::_nodename; |
709 | |
716 | |
710 | my $profile = AnyEvent::MP::Config::find_profile $name; |
717 | my $profile = AnyEvent::MP::Config::find_profile $name, @ARGV; |
|
|
718 | @ARGV = (); |
711 | |
719 | |
712 | # make it look nicer: |
720 | # make it look nicer: |
713 | delete $profile->{profile}; |
721 | delete $profile->{profile}; |
714 | delete $profile->{parent}; |
722 | delete $profile->{parent}; |
715 | |
723 | |
716 | print JSON::XS->new->pretty->encode ($profile); |
724 | print JSON::XS->new->pretty->encode ($profile); |
717 | }, |
725 | }, |
|
|
726 | |
|
|
727 | # undocumented |
|
|
728 | _resolve => sub { |
|
|
729 | print +(join ",", (AnyEvent::MP::Kernel::_resolve shift @ARGV)->recv), "\n"; |
|
|
730 | }, |
718 | ); |
731 | ); |
719 | |
732 | |
720 | sub docmd { |
733 | sub docmd { |
721 | my $cmd = shift @ARGV; |
734 | my $cmd = shift @ARGV; |
722 | |
735 | |