… | |
… | |
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 | |
… | |
… | |
123 | Care has been taken to load (almost) no modules other than |
124 | Care has been taken to load (almost) no modules other than |
124 | L<AnyEvent::Watchdog> and the modules it loads, so everything (including |
125 | L<AnyEvent::Watchdog> and the modules it loads, so everything (including |
125 | the L<AnyEvent::MP> modules themselves) will be freshly loaded on restart, |
126 | the L<AnyEvent::MP> modules themselves) will be freshly loaded on restart, |
126 | which makes upgrading everything except the perl binary easy. |
127 | which makes upgrading everything except the perl binary easy. |
127 | |
128 | |
|
|
129 | =item restart <node> |
|
|
130 | |
|
|
131 | Restarts the node using C<AnyEvent::Watchdog::Util::restart>. This works |
|
|
132 | for nodes started by C<aemp run>, but also for any other node that uses |
|
|
133 | L<AnyEvent::Watchdog>. |
|
|
134 | |
128 | =back |
135 | =back |
129 | |
136 | |
130 | =head2 PROTOCOL COMMANDS |
137 | =head2 PROTOCOL COMMANDS |
131 | |
138 | |
132 | These commands actually communicate with other nodes. They all use a node |
139 | These 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 | |
336 | Sets or replaces the list of services, which must be specified as a |
343 | Sets or replaces the list of services, which must be specified as a |
337 | comma-separated list. |
344 | comma-separated list or a JSON array. |
338 | |
345 | |
339 | Each entry in the list is interpreted as either a module name to |
346 | Each string entry in the list is interpreted as either a module name to |
340 | load (when it ends with C<::>) or a function to call (all other |
347 | load (when it ends with C<::>) or a function to call (all other cases). |
|
|
348 | |
|
|
349 | Each entry which is an array itself (you need to use JSON format to |
|
|
350 | specify those) is interpreted as a function name and the arguments to |
|
|
351 | pass. |
|
|
352 | |
341 | cases). The algorithm to find the function is the same as used for C<< |
353 | The algorithm to find the function is the same as used for C<< |
342 | L<AnyEvent::MP>::spawn >>. |
354 | L<AnyEvent::MP>::spawn >>. |
|
|
355 | |
|
|
356 | Example: run the globa service (which runs anyway, but this doesn't hurt). |
|
|
357 | |
|
|
358 | aemp setservices AnyEvent::MP::Global:: |
|
|
359 | |
|
|
360 | Example: 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 | |
346 | Removes the service list again, which means it is inherited again from |
366 | Removes the service list again, which means it is inherited again from |
347 | it's parent profile, or stays unset. |
367 | it'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 | |
|
|
551 | sub 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 | |
531 | sub docmd; |
568 | sub docmd; |
532 | |
569 | |
533 | our %CMD = ( |
570 | our %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"; |