ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/bin/aemp
(Generate patch)

Comparing AnyEvent-MP/bin/aemp (file contents):
Revision 1.36 by root, Fri Sep 4 21:46:10 2009 UTC vs.
Revision 1.37 by root, Sat Sep 5 22:47:08 2009 UTC

11 # protocol commands 11 # protocol commands
12 aemp snd <port> <arg...> # send a message 12 aemp snd <port> <arg...> # send a message
13 aemp mon <port> # wait till port is killed 13 aemp mon <port> # wait till port is killed
14 aemp rpc <port> <arg...> # send message, append reply 14 aemp rpc <port> <arg...> # send message, append reply
15 aemp eval <node> <expr...> # evaluate expression 15 aemp eval <node> <expr...> # evaluate expression
16 aemp trace <nodeid> # trace the network topology 16 aemp trace <node> # trace the network topology
17 17
18 # run a node 18 # run a node
19 aemp run configure_args... # run a node 19 aemp run configure_args... # run a node
20 aemp restart <node> # restart a node if running under watchdog
20 21
21 # node configuration: node ID 22 # node configuration: node ID
22 aemp setnodeid <nodeid> # configure the real node id 23 aemp setnodeid <nodeid> # configure the real node id
23 aemp delnodeid # reset node id to default (= inherit) 24 aemp delnodeid # reset node id to default (= inherit)
24 25
123Care has been taken to load (almost) no modules other than 124Care has been taken to load (almost) no modules other than
124L<AnyEvent::Watchdog> and the modules it loads, so everything (including 125L<AnyEvent::Watchdog> and the modules it loads, so everything (including
125the L<AnyEvent::MP> modules themselves) will be freshly loaded on restart, 126the L<AnyEvent::MP> modules themselves) will be freshly loaded on restart,
126which makes upgrading everything except the perl binary easy. 127which makes upgrading everything except the perl binary easy.
127 128
129=item restart <node>
130
131Restarts the node using C<AnyEvent::Watchdog::Util::restart>. This works
132for nodes started by C<aemp run>, but also for any other node that uses
133L<AnyEvent::Watchdog>.
134
128=back 135=back
129 136
130=head2 PROTOCOL COMMANDS 137=head2 PROTOCOL COMMANDS
131 138
132These commands actually communicate with other nodes. They all use a node 139These commands actually communicate with other nodes. They all use a node
332=over 4 339=over 4
333 340
334=item setservices <initfunc>... 341=item setservices <initfunc>...
335 342
336Sets or replaces the list of services, which must be specified as a 343Sets or replaces the list of services, which must be specified as a
337comma-separated list. 344comma-separated list or a JSON array.
338 345
339Each entry in the list is interpreted as either a module name to 346Each string entry in the list is interpreted as either a module name to
340load (when it ends with C<::>) or a function to call (all other 347load (when it ends with C<::>) or a function to call (all other cases).
348
349Each entry which is an array itself (you need to use JSON format to
350specify those) is interpreted as a function name and the arguments to
351pass.
352
341cases). The algorithm to find the function is the same as used for C<< 353The algorithm to find the function is the same as used for C<<
342L<AnyEvent::MP>::spawn >>. 354L<AnyEvent::MP>::spawn >>.
355
356Example: run the globa service (which runs anyway, but this doesn't hurt).
357
358 aemp setservices AnyEvent::MP::Global::
359
360Example: call the mymod::myfun function with arguments 1, 2 and 3.
361
362 aemp setservices '[["mymod::myfun", 1,2,3]]'
343 363
344=item delservices 364=item delservices
345 365
346Removes the service list again, which means it is inherited again from 366Removes the service list again, which means it is inherited again from
347it's parent profile, or stays unset. 367it's parent profile, or stays unset.
526 snd $reply, seed => $node; 546 snd $reply, seed => $node;
527 547
528 $cv->recv; 548 $cv->recv;
529} 549}
530 550
551sub node_eval {
552 my ($node, $expr) = @_;
553
554 init;
555
556 my $cv = AE::cv;
557 my $to = AE::timer 5, 0, sub { exit 1 };
558 AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv };
559 mon $node, $cv;
560
561 my ($err, @res) = $cv->recv;
562
563 die $err if length $err;
564
565 print +(substr JSON::XS->new->encode (\@res), 1, -1), "\n";
566}
567
531sub docmd; 568sub docmd;
532 569
533our %CMD = ( 570our %CMD = (
534 snd => sub { 571 snd => sub {
535 my $port = shift @ARGV; 572 my $port = shift @ARGV;
567 }, 604 },
568 605
569 eval => sub { 606 eval => sub {
570 my $node = node_of shift @ARGV; 607 my $node = node_of shift @ARGV;
571 my $expr = join " ", @ARGV; @ARGV = (); 608 my $expr = join " ", @ARGV; @ARGV = ();
572 init; 609 node_eval $node, $expr;
573
574 my $cv = AE::cv;
575 my $to = AE::timer 5, 0, sub { exit 1 };
576 AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv };
577 mon $node, $cv;
578
579 my ($err, @res) = $cv->recv;
580
581 die $err if length $err;
582
583 print +(substr JSON::XS->new->encode (\@res), 1, -1), "\n";
584 }, 610 },
585 611
586 trace => sub { 612 trace => sub {
587 @ARGV >= 1 613 @ARGV >= 1
588 or die "node id missing\n"; 614 or die "node id missing\n";
589 615
590 trace shift @ARGV; 616 trace shift @ARGV;
617 },
618 restart => sub {
619 my $node = node_of shift @ARGV;
620 node_eval $node, "AnyEvent::Watchdog::Util::restart";
591 }, 621 },
592 622
593 setnodeid => sub { 623 setnodeid => sub {
594 @ARGV >= 1 624 @ARGV >= 1
595 or die "shared secret missing\n"; 625 or die "shared secret missing\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines