Proper way of doing memcache flush and reloadxml/reloadacl

Status
Not open for further replies.

mutt

New Member
May 10, 2018
29
0
1
41
I'm about to embark on building a new save mechanism, but before I do I thought I'd ask the smart people.

When I hit save in the GUI, it does a memcache flush, reloadxml and/or reloadacl. How do I disperse that across multiple servers? Say n+1 other servers.

Currently I just have a bunch of shells open and do it manually, but its sort of annoying. I was thinking of doing something like just watching the freeswitch.log, detecting the action save and the running the commands. It's a kludge, but it would work.
 

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,044
565
113
There is a file called ha_monitor or something in the lua directory that does this sort of thing, we use it for clustering.

Forget any N+1 idea, its not going to work. You will get limited success but things like call transfer queueing and a bunch of other things that are needed for day to day running of a PBX will break.
 

mutt

New Member
May 10, 2018
29
0
1
41
n+1 works for what I'm after. i'm not doing anything other than the most basic incoming/outgoing A to B
 

mutt

New Member
May 10, 2018
29
0
1
41
I've found two versions of ha_monitor, and configured them both. i installed and enabled xml_rpc (not default installed)
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN

I've also tested credentials through my web browser. They work.

I can't find anything on this thing:
/var/www/fusionpbx# grep -ilR ha_monitor *
resources/install/scripts/ha_monitor.lua

so both are:
/var/www/fusionpbx/resources/install/scripts/ha_monitor.lua
/usr/share/freeswitch/scripts/ha_monitor.lua

XML RPC Running Stop True XML Remote Procedure Calls. Issue commands from your web application.

Any more bread crumbs available? I feel like the "right" way is close.
 

mutt

New Member
May 10, 2018
29
0
1
41
Here's a quick script I spent a solid 5 minutes on. It does what I need, and I'll just build this into the save button on fusion.

Perl:
#!/usr/bin/perl
# Quick and dirty flush, reload, and rescan for multiple servers, using XMLRPC
# By mutt (PBXforums.com)

use warnings;
use strict;
use RPC::XML::Client;
use Data::Dumper;
my @servers = ( '1.2.3.4', '5.6.7.8' );

foreach my $server (@servers) {
    my $client = new RPC::XML::Client("http://$server:8080/RPC2");

    my $flush     = RPC::XML::request->new( 'freeswitch.api', 'memcache',  'flush' );
    my $reloadxml = RPC::XML::request->new( 'freeswitch.api', 'reloadxml', '' );
    my $reloadacl = RPC::XML::request->new( 'freeswitch.api', 'reloadacl', '' );
    my $listgw    = RPC::XML::request->new( 'freeswitch.api', 'sofia',     'profile internal gwlist' );
    $client->credentials( "freeswitch", "freeswitch", "works" );

    print "Server: $server\n";
    print "---------------\n";

    my $res   = $client->send_request($flush);
    my $value = $res->value;
    print "Memcache Result: $value";

    $res   = $client->send_request($reloadxml);
    $value = $res->value;
    print "ReloadXML: $value";

    $res   = $client->send_request($reloadacl);
    $value = $res->value;
    print "ReloadACL: $value";

    $res   = $client->send_request($listgw);
    $value = $res->value;
    my @gw = split( / /, $value );

    foreach my $gw (@gw) {
        my $cmd   = RPC::XML::request->new( 'freeswitch.api', 'sofia', "profile internal killgw $gw" );
        my $res   = $client->send_request($cmd);
        my $value = $res->value;
        print "Kill GW Result (no dropped calls): $value";
    }

    my $rescan = RPC::XML::request->new( 'freeswitch.api', 'sofia', "profile internal rescan" );
    $res   = $client->send_request($rescan);
    $value = $res->value;
    print "Rescan GW: $value";
    print "\n";
}
 

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,044
565
113
I do it like this:

cp /usr/share/freeswitch/scripts/ha_monitor.lua /usr/share/freeswitch/scripts/ha_monitor2.lua

Edit it and change top bit to:
Code:
--! @todo move `servers` table to `local.lua` file
servers = {}
servers[#servers + 1] = {
        method   = 'curl';
        username = "freeswitch"; <----- XML RPC Username
        password = "Yourpassword"; <----- XML RPC Password
        hostname = "Yourhost1";
        port     = "Yourport"; <----- XML RPC Port
}
servers[#servers + 1] = {
        method   = 'curl';
        username = "freeswitch";
        password = "Yourpassword";
        hostname = "Yourhost2";
        port     = "Yourport";
}

etc, etc

Then in /etc/freeswitch/autoload_configs/lua.conf.xml

Add a parameter down the bottom:
<param name="startup-script" value="ha_monitor2.lua"/>

You will need to change the default xmlrpc user and password in Advanced/Settings

Don't just edit the existing ha_monitor.lua as it will get overwritten at upgrade as I have just found out!

Now when you memcache flush, it will do it on all servers. If you read the file you should be able to see hoe it could be extended. Moteus had it restarting remote gateways etc.
 
Status
Not open for further replies.