Steve Simms steve
Tue Jan 4 19:54:01 PST 2005
I've been using the altperl scripts to get Slony working on my machines, and
would like to work on them so that they are more configurable, and give more
detailed help.

As an example, I've included my modified slon_start.pl.  I've rewritten
enough of it that I decided this would be more useful than a diff, though I
could send that as well if you want to commit some or all of the changes.

Here are the major changes I've made:

- Added a --sleep option, so that the $SLEEPTIME between watchdog checks is
configurable

- Added a --config option, so that the slon.env file doesn't have to be in
the current directory or Perl's @INC.
    Example: slon_start.pl --config /etc/slony/slon.env

- Added a --watchdog|--nowatchdog process in case you don't want to start
the watchdog process for some reason

- Included all of these options in the usage statement (this is also
displayed if you pass "--help")

Minor changes:

- Allow "node1" to be passed as "1" instead (either form works).

- Require only one node number, since that's all slon_start.pl will accept
(previously, extra arguments were silently ignored)

- Changed "#!perl" to "#!/usr/bin/perl".  The former doesn't work on RH8 or
Fedora Core 1...  I'm not sure this is much of an improvement, though.
Suggestions, anyone?

- Minor reformatting, trying to follow the overall style of the file.

Is some or all of this useful?  If I offer similar changes to other files in
this directory, are they likely to be committed?

Thanks,
Steve Simms

-- 
Steve Simms <steve at deefs.net>
http://www.deefs.net
-------------- next part --------------
#!/usr/bin/perl
# $Id: slon_start.pl,v 1.5 2004/09/09 17:04:07 cbbrowne Exp $
# Author: Christopher Browne
# Copyright 2004 Afilias Canada

use Getopt::Long;

# Defaults
$START_WATCHDOG = 1;          # Whether or not the watchdog process should be started
$SLEEP_TIME     = 30;         # Number of seconds for watchdog to sleep
$SLON_ENV_FILE  = 'slon.env'; # Where to find the slon.env file
$SHOW_USAGE     = 0;          # Show usage, then quit

# Read command-line options
GetOptions("config=s"  => \$SLON_ENV_FILE,
	   "watchdog!" => \$START_WATCHDOG,
	   "sleep=i"   => \$SLEEP_TIME,
	   "help"      => \$SHOW_USAGE);

require 'slon-tools.pm';
require $SLON_ENV_FILE;

my $USAGE =
"Usage: slon_start.pl [--config file] [--watchdog|--nowatchdog]
       [--sleep seconds] node#

    --config file    Location of the slon.env file (default: Perl's \@INC)

    --watchdog       Start a watchdog process after starting the slon
                     daemon (default)

    --nowatchdog     Do not start a watchdog process

    --sleep seconds  Number of seconds for the watchdog process to sleep
                     between checks (default 30)

";

if ($SHOW_USAGE or scalar(@ARGV) != 1) {
  die $USAGE;
}

$node = $ARGV[0];

# Node can be passed either as "node1" or just "1"
if ($node =~ /^(?:node)?(\d+)$/) {
  $node = "node$1";
  $nodenum = $1;
} else {
  die $USAGE;
}

$pid = get_pid($node);
if ($pid) {
  die "Slon is already running for the '$SETNAME' set\n";
}

my $dsn    = $DSN[$nodenum];
my $dbname = $DBNAME[$nodenum];
start_slon($nodenum);
$pid = get_pid($node);

unless ($pid) {
  print "Slon failed to start for cluster $SETNAME, node $node\n";
} else {
  print "Slon successfully started for cluster $SETNAME, node $node\n";
  print "PID [$pid]\n";
  if ($START_WATCHDOG) {
    print "Start the watchdog process as well...\n";
    system "perl slon_watchdog.pl $node $SLEEP_TIME &";
  }
}


More information about the Slony1-general mailing list