Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Recommendation for a persistent perl solution?

by nysus (Parson)
on May 25, 2020 at 18:41 UTC ( #11117243=note: print w/replies, xml ) Need Help??

in reply to Re: Recommendation for a persistent perl solution?
in thread Recommendation for a persistent perl solution?

Thanks for sharing your advice. I have been talking to the lead developer. Though Rex doesn't out of the box run like a daemon, he says he has a method he uses that basically turns it into one by creating a task that waits for incoming requests. I'm going to investigate that route.

I also created my own little hack that does some symlink/bash trickery that loads a different, pared-down Rexfile when local commands are run so the load time is improved. 1/2 second response isn't perfect, but I can live with it. It's much better than 2.5 seconds.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re^2: Recommendation for a persistent perl solution?

Replies are listed 'Best First'.
Re^3: Recommendation for a persistent perl solution? (Net::DBus micro-tutorial)
by duelafn (Parson) on May 26, 2020 at 14:31 UTC

    Well, for fun I poked at Net::DBus, this will give you a service:

    use 5.020; use strict; use warnings; package My::Dog::Rex; use Net::DBus::Exporter qw(; use base qw(Net::DBus::Object); # use Rex -feature => [qw/1.4/]; dbus_method("walk_dog", [], []); sub walk_dog { my $self = shift; say "Walking the dog"; # user "root"; # password "ch4ngem3"; # # desc "Show system information"; # task "sysinfo", sub { # say run "uname -a"; # }; } 1; package My::Rex::Service; use base qw(Net::DBus::Service); sub new { my $class = shift; my $self = $class->SUPER::new(@_); My::Dog::Rex->new($self, "/my/dog/rex"); return $self; } package main; use Net::DBus; use Net::DBus::Reactor; my $bus = Net::DBus->session; my $rex = My::Rex::Service->new($bus, ""); Net::DBus::Reactor->main->run; exit 0;

    This is how you would trigger methods (from a separate script)

    use 5.020; use strict; use warnings; use Net::DBus; my $bus = Net::DBus->session; my $rex = $bus->get_service("")->get_object("/my/dog/rex"); $rex->walk_dog;

    And when you want to run on the system bus instead of the user's session bus, change all the ->session to ->system, add the following to "/etc/dbus-1/system.d/" and then run "systemctl reload dbus.service"

    <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuratio +n 1.0//EN" " +td"> <busconfig> <!-- Root can own or use the Rex service --> <policy user="root"> <allow own=""/> <allow send_destination=""/> <allow receive_sender=""/> </policy> <!-- Nobody else can do anything --> <policy context="default"> <deny send_destination=""/> <deny receive_sender=""/> </policy> </busconfig>

    Good Day,

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117243]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-05-17 17:02 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (68 votes). Check out past polls.