Start slon passing with a slon configuration file
authorLuiz K. Matsumura <luiz.matsumura@gmail.com>
Thu, 25 Oct 2012 14:12:36 +0000 (12:12 -0200)
committerLuiz K. Matsumura <luiz.matsumura@gmail.com>
Thu, 8 Nov 2012 22:03:25 +0000 (20:03 -0200)
Implement a new parameter on node configuration to allow to specify
a slon configuration file to be used to start the slon daemon

adjusted slon_start and get_pid functions to consider the new start string

tools/altperl/slon-tools.pm
tools/altperl/slon_tools.conf-sample

index 9d0b221462757fe06c5db7ef6f5b591dedf99eb5..7dcafedafb37d7a0699fcbbe42ad6670c4120fda 100644 (file)
@@ -15,7 +15,8 @@ sub add_node {
                parent => undef,
                noforward => undef,
                sslmode => undef,
-               options => undef
+               options => undef,
+               config => undef
               );
   my $K;
   while ($K= shift) {
@@ -71,6 +72,10 @@ sub add_node {
   if ($options) {
     $OPTIONS[$node] = $options;
   }
+  my $config = $PARAMS{ 'config' };
+  if ($config) {
+    $CONFIG[$node] = $config;
+  }
 }
 
 # This is the usual header to a slonik invocation that declares the
@@ -124,9 +129,16 @@ sub get_pid {
   my $nodenum = $1;
   my $pid;
   my $tpid;
-  my ($dbname, $dbport, $dbhost) = ($DBNAME[$nodenum], $PORT[$nodenum], $HOST[$nodenum]);
+  my $command;
+  my ($dsn, $config) = ($DSN[$nodenum], $CONFIG[$nodenum]);
   #  print "Searching for PID for $dbname on port $dbport\n";
-  my $command =  ps_args() . "| egrep \"[s]lon .*$CLUSTER_NAME \" | egrep \"host=$dbhost dbname=$dbname.*port=$dbport\" | sort -n | awk '{print \$2}'";
+  if ($config) {
+    my $config_regexp = quotemeta( $config );
+    $command =  ps_args() . "| egrep \"[s]lon -f $config_regexp \" | sort -n | awk '{print \$2}'";
+  } else {
+    $dsn = quotemeta($dsn);
+    $command =  ps_args() . "| egrep \"[s]lon .* $CLUSTER_NAME \" | egrep \"$dsn\" | sort -n | awk '{print \$2}'";
+  }
   #print "Command:\n$command\n";
   open(PSOUT, "$command|");
   while ($tpid = <PSOUT>) {
@@ -156,12 +168,17 @@ sub get_node_name {
 
 sub start_slon {
   my ($nodenum) = @_;
-  my ($dsn, $dbname, $opts) = ($DSN[$nodenum], $DBNAME[$nodenum], $OPTIONS[$nodenum]);
+  my ($dsn, $dbname, $opts, $config) = ($DSN[$nodenum], $DBNAME[$nodenum], $OPTIONS[$nodenum], $CONFIG[$nodenum]);
   $SYNC_CHECK_INTERVAL ||= 1000;
   $DEBUGLEVEL ||= 0;
   $LOG_NAME_SUFFIX ||= '%Y-%m-%d';
   system("mkdir -p $LOGDIR/node$nodenum");
-  my $cmd = "@@SLONBINDIR@@/slon -s $SYNC_CHECK_INTERVAL -d$DEBUGLEVEL $opts $CLUSTER_NAME '$dsn' ";
+  my $cmd;
+  if ($config) {
+     $cmd = "@@SLONBINDIR@@/slon -f $config ";
+  } else {
+     $cmd = "@@SLONBINDIR@@/slon -s $SYNC_CHECK_INTERVAL -d$DEBUGLEVEL $opts $CLUSTER_NAME '$dsn' ";
+  }
   my $logfilesuffix = POSIX::strftime( "$LOG_NAME_SUFFIX",localtime );
   chomp $logfilesuffix;
 
index 8d96b5973213805cc492aa8e284e7505e098e736..f4201c157d3c429f02d8bbab0bee82281dd4534e 100644 (file)
@@ -55,21 +55,24 @@ if ($ENV{"SLONYNODES"}) {
             dbname   => 'database',
             port     => 5432,
             user     => 'postgres',
-             password => '');
+             password => '',
+             config   => '/path/to/node1_config_file.conf');
 
     add_node(node     => 2,
             host     => 'server2',
             dbname   => 'database',
             port     => 5432,
             user     => 'postgres',
-             password => '');
+             password => '',
+             config   => '/path/to/node2_config_file.conf');
 
     add_node(node     => 3,
             host     => 'server3',
             dbname   => 'database',
             port     => 5432,
             user     => 'postgres',
-             password => '');
+             password => '',
+             config   => '/path/to/node3_config_file.conf');
 
     # If the node should only receive event notifications from a
     # single node (e.g. if it can't access the other nodes), you can
@@ -82,7 +85,8 @@ if ($ENV{"SLONYNODES"}) {
             dbname   => 'database',
             port     => 5432,
             user     => 'postgres',
-             password => '');
+             password => '',
+             config   => '/path/to/node4_config_file.conf');
 
 }
 
@@ -92,7 +96,7 @@ if ($ENV{"SLONYNODES"}) {
 $SLONY_SETS = {
 
     # A unique name for the set
-    "set1" => {
+    "set1_name" => {
 
        # The set_id, also unique
        "set_id" => 1,