make WebGUI::Config more reliable with relative paths and chdir. fixes forking upgrade.
This commit is contained in:
parent
bb4c576f66
commit
ffd685c36a
2 changed files with 23 additions and 14 deletions
|
|
@ -16,6 +16,7 @@ package WebGUI::Config;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Class::InsideOut qw(readonly id register);
|
use Class::InsideOut qw(readonly id register);
|
||||||
|
use Cwd ();
|
||||||
use base 'Config::JSON';
|
use base 'Config::JSON';
|
||||||
|
|
||||||
my %config = ();
|
my %config = ();
|
||||||
|
|
@ -148,14 +149,14 @@ A boolean value that when set to true tells the config system not to store the c
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $webguiPath = shift;
|
my $webguiPath = Cwd::realpath(shift);
|
||||||
my $filename = shift;
|
my $filename = shift;
|
||||||
my $noCache = shift;
|
my $noCache = shift;
|
||||||
my $fullPath = $webguiPath.'/etc/'.$filename;
|
my $fullPath = $webguiPath.'/etc/'.$filename;
|
||||||
if (exists $config{$filename}) {
|
if (exists $config{$filename}) {
|
||||||
return $config{$filename};
|
return $config{$filename};
|
||||||
} else {
|
} else {
|
||||||
my $self = Config::JSON->new($webguiPath."/etc/".$filename);
|
my $self = Config::JSON->new($fullPath);
|
||||||
register($self, $class);
|
register($self, $class);
|
||||||
$webguiRoot{id $self} = $webguiPath;
|
$webguiRoot{id $self} = $webguiPath;
|
||||||
$config{$filename} = $self unless $noCache;
|
$config{$filename} = $self unless $noCache;
|
||||||
|
|
@ -181,9 +182,9 @@ The path to the WebGUI installation.
|
||||||
sub readAllConfigs {
|
sub readAllConfigs {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $webguiPath = shift;
|
my $webguiPath = shift;
|
||||||
opendir(DIR,$webguiPath."/etc");
|
opendir my $dh, $webguiPath."/etc";
|
||||||
my @files = readdir(DIR);
|
my @files = readdir $dh;
|
||||||
closedir(DIR);
|
closedir $dh;
|
||||||
my %configs;
|
my %configs;
|
||||||
foreach my $file (@files) {
|
foreach my $file (@files) {
|
||||||
next
|
next
|
||||||
|
|
@ -191,12 +192,14 @@ sub readAllConfigs {
|
||||||
|| $file =~ /^\./
|
|| $file =~ /^\./
|
||||||
|| $file eq 'log.conf'
|
|| $file eq 'log.conf'
|
||||||
|| $file eq 'spectre.conf';
|
|| $file eq 'spectre.conf';
|
||||||
$configs{$file} = eval{WebGUI::Config->new($webguiPath,$file)};
|
eval {
|
||||||
|
$configs{$file} = WebGUI::Config->new($webguiPath,$file)
|
||||||
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
warn "Config file ".$file." looks to be corrupt or have a syntax error.";
|
warn "Config file ".$file." looks to be corrupt or have a syntax error.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return \%configs;
|
return \%configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,12 +226,18 @@ foreach my $filename (keys %config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($upgrade{$upgrade}{pl} ne "") {
|
if ($upgrade{$upgrade}{pl} ne "") {
|
||||||
my $cmd = $perl." ".$upgrade{$upgrade}{pl}." --configFile=".$filename;
|
my $pid = fork;
|
||||||
$cmd .= " --quiet" if ($quiet);
|
if (!$pid) {
|
||||||
if (system($cmd)) {
|
@ARGV = ("--configFile=$filename", $quiet ? ('--quiet') : ());
|
||||||
print "\tProcessing upgrade executable failed!\n";
|
$0 = $upgrade{$upgrade}{pl};
|
||||||
fatalError();
|
do $0;
|
||||||
}
|
exit;
|
||||||
|
}
|
||||||
|
waitpid $pid, 0;
|
||||||
|
if ($?) {
|
||||||
|
print "\tProcessing upgrade executable failed!\n";
|
||||||
|
fatalError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$config{$filename}{version} = $upgrade{$upgrade}{to};
|
$config{$filename}{version} = $upgrade{$upgrade}{to};
|
||||||
$notRun = 0;
|
$notRun = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue