summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
621e81d)
Flag "-l" was previously used for a lockfile; this has now changed to "-w", however lockfile functionality should not be needed.
-$ pg_sched.pl -h <db host> -p <db port> -d <db name> -U <db user> -n <schema> -t <table> -cl <slony clustername> -m <master sets> -l <lock file>
+$ pg_sched.pl -h <db host> -p <db port> -d <db name> -U <db user> -n <schema> -t <table> -cl <slony clustername> -m <master sets> -w <lock file> -l <logfile>
-h Hostname of database containing schedule table
DEFAULT = localhost
-p Listening port of database containing schedule table
-h Hostname of database containing schedule table
DEFAULT = localhost
-p Listening port of database containing schedule table
DEFAULT = auto
-m Comma separated list of slony sets on the master. 'all' for all
DEFAULT = all
DEFAULT = auto
-m Comma separated list of slony sets on the master. 'all' for all
DEFAULT = all
- -l Lockfile used to prevent concurrent execution of tasks.
+ -w Lockfile used to prevent concurrent execution of tasks.
+ -l File to log to.
+ DEFAULT = log to STDOUT instead
Add an entry to run from cron something like:
```cron
Add an entry to run from cron something like:
```cron
- * * * * * myuser /home/myuser/pg_sched.pl -d mydb -U pg_sched >> /var/log/pg_sched.log 2>&1
+ * * * * * myuser /home/myuser/pg_sched.pl -d mydb -U pg_sched -l /var/log/pg_sched.log > /dev/null 2>&1
```
Insert a row into the table to create a task, e.g:
```
Insert a row into the table to create a task, e.g:
my $g_dbtable = 'pg_sched';
my $g_clname = 'auto';
my $g_sets = 'all';
my $g_dbtable = 'pg_sched';
my $g_clname = 'auto';
my $g_sets = 'all';
-my $g_usage = "pg_sched.pl -h <db host> -p <db port> -d <db name> -U <db user> -n <schema> -t <table> -cl <slony clustername> -m <master sets> -l <lock file>
+my $g_usage = "pg_sched.pl -h <db host> -p <db port> -d <db name> -U <db user> -n <schema> -t <table> -cl <slony clustername> -m <master sets> -w <lock file> -l <logfile>
-h Hostname of database containing schedule table
DEFAULT = $g_dbhost
-p Listening port of database containing schedule table
-h Hostname of database containing schedule table
DEFAULT = $g_dbhost
-p Listening port of database containing schedule table
DEFAULT = $g_clname
-m Comma separated list of slony sets on the master. 'all' for all
DEFAULT = $g_sets
DEFAULT = $g_clname
-m Comma separated list of slony sets on the master. 'all' for all
DEFAULT = $g_sets
- -l Lockfile used to prevent concurrent execution of tasks.
+ -w Lockfile used to prevent concurrent execution of tasks.
+ -l File to log to.
+ DEFAULT = log to STDOUT instead
my @g_pronames;
my $g_errors;
my $g_lockfile;
my @g_pronames;
my $g_errors;
my $g_lockfile;
-die $g_usage unless GetOptions(\%opt, 'host|H=s', 'port|p=i', 'dbname|d=s', 'user|U=s', 'schema|n=s', 'table|t=s', 'lockfile|l=s', 'clname|cl=s', 'msets|m=s');
+die $g_usage unless GetOptions(\%opt, 'host|H=s', 'port|p=i', 'dbname|d=s', 'user|U=s', 'schema|n=s', 'table|t=s', 'lockfile|w=s', 'clname|cl=s', 'msets|m=s', 'logfile|l=s');
if (defined($opt{host})) {
$g_dbhost = $opt{host};
if (defined($opt{host})) {
$g_dbhost = $opt{host};
if (defined($opt{msets})) {
$g_sets = $opt{msets};
}
if (defined($opt{msets})) {
$g_sets = $opt{msets};
}
+if (defined($opt{logfile})) {
+ $g_logfile = $opt{logfile};
+}
# If lockfile supplied check if the script is already running
if (defined($g_lockfile)) {
# If lockfile supplied check if the script is already running
if (defined($g_lockfile)) {
@g_pronames = (@g_pronames, loadWork($g_dbhost, $g_dbport, $g_dbname, $g_dbuser, $g_dbschema, $g_dbtable, $g_origin, $target_dbname));
}
# Do all the work we have collected for all databases
@g_pronames = (@g_pronames, loadWork($g_dbhost, $g_dbport, $g_dbname, $g_dbuser, $g_dbschema, $g_dbtable, $g_origin, $target_dbname));
}
# Do all the work we have collected for all databases
-$g_errors = doWork(\@g_pronames, $g_dbhost, $g_dbport, $g_dbname, $g_dbuser, $g_dbschema, $g_dbtable);
+$g_errors = doWork(\@g_pronames, $g_dbhost, $g_dbport, $g_dbname, $g_dbuser, $g_dbschema, $g_dbtable, $g_logfile);
if ($g_errors > 0) {
warn ("ERROR: Encountered $g_errors errors processing the schedule\n") if $@;
if ($g_errors > 0) {
warn ("ERROR: Encountered $g_errors errors processing the schedule\n") if $@;
+sub logFile {
+ my $logfile = shift;
+ my $message = shift;
+
+ eval {
+ open(LOGFILE, ">>", $logfile);
+ flock(LOGFILE, 2);
+ print LOGFILE $message;
+ close (LOGFILE);
+ };
+ warn ("WARNING: unable to log to file $logfile\n") if $@;
+}
+
sub loadDatabases{
my $dbhost = shift;
my $dbport = shift;
sub loadDatabases{
my $dbhost = shift;
my $dbport = shift;
my $dbuser = shift;
my $dbschema = shift;
my $dbtable = shift;
my $dbuser = shift;
my $dbschema = shift;
my $dbtable = shift;
my @workers;
my @worker_result;
my $bad = 0;
foreach my $prodef (@$pronames) {
my @workers;
my @worker_result;
my $bad = 0;
foreach my $prodef (@$pronames) {
- my ($t) = threads->new(\&runWorker, $prodef, $dbhost, $dbport, $dbname, $dbuser, $dbschema, $dbtable);
+ my ($t) = threads->new(\&runWorker, $prodef, $dbhost, $dbport, $dbname, $dbuser, $dbschema, $dbtable, $logfile);
push(@workers,$t);
}
foreach (@workers) {
@worker_result = $_->join;
if ($worker_result[0] == true) {
push(@workers,$t);
}
foreach (@workers) {
@worker_result = $_->join;
if ($worker_result[0] == true) {
- print("$worker_result[1] [SUCCEEDED]\n");
+ print("$worker_result[1] [SUCCEEDED]\n") if (!defined($logfile));
- print("$worker_result[1] [FAILED]\n");
+ print("$worker_result[1] [FAILED]\n") if (!defined($logfile));
my $dbuser = shift;
my $dbschema = shift;
my $dbtable = shift;
my $dbuser = shift;
my $dbschema = shift;
my $dbtable = shift;
$detail .= 'already running PID ' . @$prodef[8];
}
$detail .= 'already running PID ' . @$prodef[8];
}
+ if (defined($logfile)) {
+ logFile($logfile, $detail . ($success?' [SUCCEEDED]':' [FAILED]') . "\n");
+ }
+
return ($success, $detail);
}
return ($success, $detail);
}