use strict;
use warnings;
+use File::Temp qw(tempfile);
use Getopt::Long;
+use IO::Socket::INET;
our %options = (
'pgdata' => undef,
die(qq|Data directory $options{'pgdata'} not found or not a directory\n|);
}
-# TODO: check port not in use
+# Check specified port not in use
+my $socket = IO::Socket::INET->new(
+ LocalAddr =>'localhost',
+ LocalPort => $options{'port'},
+ Proto => 'tcp',
+ ReusePort => 1
+);
+
+if(!$socket) {
+ die qq|Port '$options{'port'}' appears to be in use\n|;
+}
+close($socket);
-# TODO: check for active instance
-# TODO: make unique log file
+my ($fh, $log_file) = tempfile( 'dump_regress_XXXXXX', TMPDIR => 1, SUFFIX => '.log', EXLOCK => 0);
+
+# check for extant pidfile in specified data directory
+# (not 100% foolproof but good enough for now)
+my $pidfile = qq|$options{'pgdata'}/postmaster.pid|;
+if(-e $pidfile) {
+ die qq|'$pidfile' exists - is another instance using the data directory?|;
+}
-my $log_dir = '/tmp/dump-regress.log';
my $pg_ctl= sprintf(
q|%s/src/bin/pg_ctl/pg_ctl -p %s/src/backend/postgres --pgdata %s -o '-p%i' -l %s -w|,
$options{'top-builddir'},
$options{'top-builddir'},
$options{'pgdata'},
$options{'port'},
- $log_dir,
+ $log_file,
);
-#print "$pg_ctl\n";exit;
+
# TODO: check success
`${pg_ctl} start`;