diff options
Diffstat (limited to 'installer')
-rw-r--r-- | installer/OpenSLX/OSSetup/Distro/Base.pm | 13 | ||||
-rw-r--r-- | installer/OpenSLX/OSSetup/Engine.pm | 75 |
2 files changed, 47 insertions, 41 deletions
diff --git a/installer/OpenSLX/OSSetup/Distro/Base.pm b/installer/OpenSLX/OSSetup/Distro/Base.pm index 39572e5d..573114e8 100644 --- a/installer/OpenSLX/OSSetup/Distro/Base.pm +++ b/installer/OpenSLX/OSSetup/Distro/Base.pm @@ -122,11 +122,6 @@ sub startSession my $self = shift; my $osDir = shift; - # ensure that the session will be finished even if the script crashes: - addCleanupFunction( - "slxos-setup::distro::chroot", sub { $self->finishSession(); } - ); - # setup a fixed locale environment to avoid warnings about unset locales # (like for instance shown by apt-get) $ENV{LC_ALL} = 'POSIX'; @@ -152,7 +147,7 @@ sub startSession # mount /proc (if we have 'mount' available) if (qx{which mount 2>/dev/null}) { - if (!-e "$osDir/proc" && !mkpath("$osDir/proc")) { + if (!-e '/proc' && !mkpath('/proc')) { die _tr("unable to create folder '%s' (%s)\n", "$osDir/proc", $!); } if (slxsystem("mount -t proc proc '/proc'")) { @@ -160,15 +155,13 @@ sub startSession } } - return; + return 1; } sub finishSession { my $self = shift; - removeCleanupFunction('slxos-setup::distro::chroot'); - # umount /proc (if we have 'umount' available) if (qx{which umount 2>/dev/null}) { if (slxsystem("umount /proc")) { @@ -176,7 +169,7 @@ sub finishSession } } - return; + return 1; } sub getDefaultPathList diff --git a/installer/OpenSLX/OSSetup/Engine.pm b/installer/OpenSLX/OSSetup/Engine.pm index 9518c74a..7fce8a59 100644 --- a/installer/OpenSLX/OSSetup/Engine.pm +++ b/installer/OpenSLX/OSSetup/Engine.pm @@ -31,6 +31,7 @@ use File::Basename; use URI; use OpenSLX::Basics; +use OpenSLX::ScopedResource; use OpenSLX::Syscall; use OpenSLX::Utils; @@ -117,8 +118,7 @@ use vars qw(%supportedDistros); }, ); -our $localHttpServerMasterPID; -our %localHttpServers; +my %localHttpServers; ################################################################################ ### interface methods @@ -132,22 +132,6 @@ sub new return bless $self, $class; } -sub DESTROY -{ - my $self = shift; - - my $httpServerPID = $localHttpServerMasterPID || '0'; - if ($httpServerPID == $$) { - # we are the master process, so we clean up all the servers that we - # have started: - while (my ($localURL, $serverInfo) = each %localHttpServers) { - vlog(1, _tr("stopping local HTTP-server for URL '%s'.", $localURL)); - kill TERM => $serverInfo->{pid}; - } - } - return; -} - sub initialize { my $self = shift; @@ -291,7 +275,11 @@ sub installVendorOS } $self->_createVendorOSPath(); - $self->_startLocalURLServersAsNeeded(); + my $httpServers = OpenSLX::ScopedResource->new({ + name => 'local-http-servers', + acquire => sub { $self->_startLocalURLServersAsNeeded(); 1 }, + release => sub { $self->_stopLocalURLServers(); 1 }, + }); my $baseSystemFile = "$self->{'vendor-os-path'}/.openslx-base-system"; if (-e $baseSystemFile) { @@ -436,7 +424,11 @@ sub updateVendorOS $self->{'vendor-os-path'}); } - $self->_startLocalURLServersAsNeeded(); + my $httpServers = OpenSLX::ScopedResource->new({ + name => 'local-http-servers', + acquire => sub { $self->_startLocalURLServersAsNeeded(); 1 }, + release => sub { $self->_stopLocalURLServers(); 1 }, + }); callInSubprocess( sub { @@ -467,7 +459,11 @@ sub startChrootedShellForVendorOS ); } - $self->_startLocalURLServersAsNeeded(); + my $httpServers = OpenSLX::ScopedResource->new({ + name => 'local-http-servers', + acquire => sub { $self->_startLocalURLServersAsNeeded(); 1 }, + release => sub { $self->_stopLocalURLServers(); 1 }, + }); callInSubprocess( sub { @@ -500,7 +496,11 @@ sub callChrootedFunctionForVendorOS ); } - $self->_startLocalURLServersAsNeeded(); + my $httpServers = OpenSLX::ScopedResource->new({ + name => 'local-http-servers', + acquire => sub { $self->_startLocalURLServersAsNeeded(); 1 }, + release => sub { $self->_stopLocalURLServers(); 1 }, + }); callInSubprocess( sub { @@ -1189,8 +1189,6 @@ sub _startLocalURLServersAsNeeded { my $self = shift; - $localHttpServerMasterPID ||= $$; - my $port = 5080; my %portForURL; foreach my $repoInfo (values %{$self->{'distro-info'}->{repository}}) { @@ -1220,6 +1218,16 @@ sub _startLocalURLServersAsNeeded return; } +sub _stopLocalURLServers +{ + my $self = shift; + + while (my ($localURL, $serverInfo) = each %localHttpServers) { + vlog(1, _tr("stopping local HTTP-server for URL '%s'.", $localURL)); + kill TERM => $serverInfo->{pid}; + } +} + sub _setupStage1A { my $self = shift; @@ -1582,15 +1590,20 @@ sub _callChrootedFunction 'updateConfig' => '?', }); - $self->{distro}->startSession($params->{chrootDir}); + my $distro = $self->{distro}; + my $distroSession = OpenSLX::ScopedResource->new({ + name => 'ossetup::distro::session', + acquire => sub { $distro->startSession($params->{chrootDir}); 1 }, + release => sub { $distro->finishSession(); 1 }, + }); - # invoke given function: - $params->{function}->(); + die $@ if ! eval { + # invoke given function: + $params->{function}->(); + $distro->updateDistroConfig() if $params->{updateConfig}; + 1; + }; - if ($params->{updateConfig}) { - $self->{'distro'}->updateDistroConfig(); - } - $self->{'distro'}->finishSession(); return; } |