migrate_workers_file [plain text]
$fileLocation = '/etc/httpd/workers.properties';
$backupFileLocation = '/etc/httpd/workers.properties.applesaved';
$defaultFileText = "ps=/\nworker.list=blojsomworker\n\n# ------------------------\n# Blojsom worker\n# ------------------------\n#\n# Worker created specifically for Blojsom.\nworker.blojsomworker.port=1279\nworker.blojsomworker.host=127.0.0.1\nworker.blojsomworker.type=ajp13\nworker.blojsomworker.lbfactor=100\n\n#\n# END workers.properties\n#\n\n";
$endWorkersText = "\n#\n# END workers.properties\n#\n";
$newBlojsomWorkerText = "\n# ------------------------\n# Blojsom worker\n# ------------------------\n#\n# Worker created specifically for Blojsom.\nworker.blojsomworker.port=1279\nworker.blojsomworker.host=127.0.0.1\nworker.blojsomworker.type=ajp13\nworker.blojsomworker.lbfactor=100\n\n";
$_ = '';
sub writeDefaultFileText {
`/bin/cp "$fileLocation" "$backupFileLocation"`;
open (WORKERSFILE, ">$fileLocation");
print WORKERSFILE $defaultFileText;
close WORKERSFILE;
}
if (open(WORKERSFILE, $fileLocation)) {
while ($line = <WORKERSFILE>) {
$_ .= $line;
}
close(WORKERSFILE);
if (!(m/worker.list=(.+)\n/)) {
writeDefaultFileText();
exit 0;
}
if ($1 =~ m/blojsomworker/) {
`/usr/bin/logger "Migration was unable to add a blojsom worker to your corrupted /etc/httpd/workers.properties file"`;
exit 0;
}
$newWorkerList .= "$1, blojsomworker";
s/worker.list=.+\n/worker.list=$newWorkerList\n/;
s/$endWorkersText//;
$_ .= $newBlojsomWorkerText;
$_ .= $endWorkersText;
`/bin/cp "$fileLocation" "$backupFileLocation"`;
`/usr/bin/logger "The previous /etc/httpd/workers.properties file has been saved as /etc/httpd/workers.properties.applesaved. The current /etc/httpd/workers.properties file now includes a blojsom worker."`;
open (WORKERSFILE, ">$fileLocation");
print WORKERSFILE $_;
close WORKERSFILE;
}
else {
`/usr/bin/logger "Migration was unable to find a /etc/httpd/workers.properties file. Saving a new one."`;
writeDefaultFileText();
}
1;