From 7926993940c0d4f8b1bab9557cf972364d782402 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Mon, 28 May 2007 21:10:57 +0000 Subject: * added support for 'local:'-URLs, which trigger the automatic start of a busybox-httpd for each repository, through which every request will be routed (thus giving access to files outside of the chroot) * renamed executeInSubprocess() to callInSubprocess() and added a real implementation of executeInSubprocess(), too * updated all settings.local.example files to reflect the new way of accessing local files git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1102 95ad53e4-c205-0410-b2fa-d234c58c8868 --- installer/OpenSLX/OSSetup/Engine.pm | 65 +++++++++++++++++++++- lib/OpenSLX/Basics.pm | 22 +++++++- lib/distro-info/fedora-6/settings.local.example | 8 +-- .../fedora-6_x86_64/settings.local.example | 8 +-- lib/distro-info/suse-10.1/settings.local.example | 7 ++- .../suse-10.1_x86_64/settings.local.example | 7 ++- lib/distro-info/suse-10.2/settings.local.example | 7 ++- .../suse-10.2_x86_64/settings.local.example | 7 ++- 8 files changed, 106 insertions(+), 25 deletions(-) diff --git a/installer/OpenSLX/OSSetup/Engine.pm b/installer/OpenSLX/OSSetup/Engine.pm index 82c93648..9d7d31ab 100644 --- a/installer/OpenSLX/OSSetup/Engine.pm +++ b/installer/OpenSLX/OSSetup/Engine.pm @@ -79,6 +79,20 @@ sub new return bless $self, $class; } +sub DESTROY +{ + my $self = shift; + + if ($self->{'local-http-server-master-pid'} == $$) { + # we are the master process, so we clean up all the servers that we + # have started: + while(my ($localURL, $pid) = each %{$self->{'local-http-servers'}}) { + vlog 1, _tr("stopping local HTTP-server for URL '%s'.", $localURL); + kill TERM => $pid; + } + } +} + sub initialize { my $self = shift; @@ -160,13 +174,15 @@ sub installVendorOS } $self->createVendorOSPath(); + $self->startLocalURLServersAsNeeded(); + my $baseSystemFile = "$self->{'vendor-os-path'}/.openslx-base-system"; if (-e $baseSystemFile) { vlog 0, _tr("found existing base system, continuing...\n"); } else { # basic setup, stage1a-c: $self->setupStage1A(); - executeInSubprocess( sub { + callInSubprocess( sub { # some tasks that involve a chrooted environment: $self->changePersonalityIfNeeded(); $self->setupStage1B(); @@ -176,7 +192,7 @@ sub installVendorOS slxsystem("touch $baseSystemFile"); # just touch the file, in order to indicate a basic system } - executeInSubprocess( sub { + callInSubprocess( sub { # another task that involves a chrooted environment: $self->changePersonalityIfNeeded(); $self->setupStage1D(); @@ -268,7 +284,10 @@ sub updateVendorOS die _tr("can't update vendor-OS '%s', since it doesn't exist!\n", $self->{'vendor-os-path'}); } - executeInSubprocess( sub { + + $self->startLocalURLServersAsNeeded(); + + callInSubprocess( sub { $self->changePersonalityIfNeeded(); $self->updateStage1D(); }); @@ -489,6 +508,14 @@ sub sortRepositoryURLs my $self = shift; my $repoInfo = shift; + if ($repoInfo->{'url'} =~ m[^local:]) { + # a local URL blocks all the others, in order to avoid causing + # (external) network traffic: + my $localURL = $repoInfo->{'url'}; + $localURL =~ s[^local:][http:]; + return [ $localURL ]; + } + my %urlInfo; # specified URL always has highest precedence: $urlInfo{$repoInfo->{url}} = 0 if defined $repoInfo->{url}; @@ -546,6 +573,38 @@ try_next_url: return @foundFiles; } +sub startLocalURLServersAsNeeded +{ + my $self = shift; + + $self->{'local-http-server-master-pid'} = $$; + + foreach my $repoInfo (values %{$self->{'distro-info'}->{repository}}) { + + next unless $repoInfo->{'url'} =~ m[^local:]; + my $localURL = $repoInfo->{url}; + if (!exists $self->{'local-http-servers'}->{$localURL}) { + my $busyboxName + = $self->hostIs64Bit() + ? 'busybox.x86_64' + : 'busybox.i586'; + my $busybox = "$openslxConfig{'share-path'}/busybox/$busyboxName"; + my $port = 5080; + if ($localURL =~ m[:(\d+)/]) { + $port = $1; + } + my $pid = executeInSubprocess( + $busybox, "httpd", + '-p', $port, + '-h', '/', + '-f' + ); + vlog 1, _tr("started local HTTP-server for URL '%s'.", $localURL); + $self->{'local-http-servers'}->{$localURL} = $pid; + } + } +} + sub setupStage1A { my $self = shift; diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm index 937c99c7..f673d279 100644 --- a/lib/OpenSLX/Basics.pm +++ b/lib/OpenSLX/Basics.pm @@ -23,7 +23,8 @@ $VERSION = 1.01; @EXPORT = qw( &openslxInit %openslxConfig %cmdlineConfig &_tr &trInit - &warn &die &executeInSubprocess &slxsystem + &warn &die + &callInSubprocess &executeInSubprocess &slxsystem &vlog &instantiateClass &addCleanupFunction &removeCleanupFunction @@ -298,7 +299,7 @@ sub _tr } # ------------------------------------------------------------------------------ -sub executeInSubprocess +sub callInSubprocess { my $childFunc = shift; @@ -323,6 +324,23 @@ sub executeInSubprocess } } +# ------------------------------------------------------------------------------ +sub executeInSubprocess +{ + my @cmdlineArgs = @_; + + my $pid = fork(); + if (!$pid) { + # child... + # ...exec the given cmdline: + exec(@cmdlineArgs); + die _tr("error in exec('%s')! (%s)", join(' ', @cmdlineArgs), $!); + } + + # parent... + return $pid; +} + # ------------------------------------------------------------------------------ sub addCleanupFunction { diff --git a/lib/distro-info/fedora-6/settings.local.example b/lib/distro-info/fedora-6/settings.local.example index 75115e1a..b41c94f8 100644 --- a/lib/distro-info/fedora-6/settings.local.example +++ b/lib/distro-info/fedora-6/settings.local.example @@ -1,7 +1,7 @@ -# Use local installation sources. -# $repository{base}->{url} = 'ftp://localhost/pub/opensuse/distribution/SL-10.1/inst-source'; -# $repository{base_update}->{url} = 'ftp://localhost/pub/suse/update/10.1'; -# +# use local installation sources +$repository{'base'}->{'url'} = "local://localhost:5080/srv/ftp/pub/opensuse/distribution/SL-10.1/inst-source"; +$repository{'base_update'}->{'url'} = "local://localhost:5082/srv/ftp/pub/suse/update/10.1"; + # Add a new selection: # $selection{'my-kde'} = "$selection{default} # foo diff --git a/lib/distro-info/fedora-6_x86_64/settings.local.example b/lib/distro-info/fedora-6_x86_64/settings.local.example index 75115e1a..b41c94f8 100644 --- a/lib/distro-info/fedora-6_x86_64/settings.local.example +++ b/lib/distro-info/fedora-6_x86_64/settings.local.example @@ -1,7 +1,7 @@ -# Use local installation sources. -# $repository{base}->{url} = 'ftp://localhost/pub/opensuse/distribution/SL-10.1/inst-source'; -# $repository{base_update}->{url} = 'ftp://localhost/pub/suse/update/10.1'; -# +# use local installation sources +$repository{'base'}->{'url'} = "local://localhost:5080/srv/ftp/pub/opensuse/distribution/SL-10.1/inst-source"; +$repository{'base_update'}->{'url'} = "local://localhost:5082/srv/ftp/pub/suse/update/10.1"; + # Add a new selection: # $selection{'my-kde'} = "$selection{default} # foo diff --git a/lib/distro-info/suse-10.1/settings.local.example b/lib/distro-info/suse-10.1/settings.local.example index 957876e8..3588750a 100644 --- a/lib/distro-info/suse-10.1/settings.local.example +++ b/lib/distro-info/suse-10.1/settings.local.example @@ -1,6 +1,7 @@ -# Use local installation sources. -$repository{base}->{url} = 'ftp://localhost/pub/opensuse/distribution/SL-10.1/inst-source'; -$repository{base_update}->{url} = 'ftp://localhost/pub/suse/update/10.1'; +# use local installation sources +$repository{'base'}->{'url'} = "local://localhost:5080/srv/ftp/pub/opensuse/distribution/SL-10.1/inst-source"; +$repository{'base_non-oss'}->{'url'} = "local://localhost:5081/srv/ftp/pub/opensuse/distribution/SL-10.1/non-oss-inst-source"; +$repository{'base_update'}->{'url'} = "local://localhost:5082/srv/ftp/pub/suse/update/10.1"; # Add a new selection: # $selection{'my-kde'} = "$selection{default} diff --git a/lib/distro-info/suse-10.1_x86_64/settings.local.example b/lib/distro-info/suse-10.1_x86_64/settings.local.example index 957876e8..3588750a 100644 --- a/lib/distro-info/suse-10.1_x86_64/settings.local.example +++ b/lib/distro-info/suse-10.1_x86_64/settings.local.example @@ -1,6 +1,7 @@ -# Use local installation sources. -$repository{base}->{url} = 'ftp://localhost/pub/opensuse/distribution/SL-10.1/inst-source'; -$repository{base_update}->{url} = 'ftp://localhost/pub/suse/update/10.1'; +# use local installation sources +$repository{'base'}->{'url'} = "local://localhost:5080/srv/ftp/pub/opensuse/distribution/SL-10.1/inst-source"; +$repository{'base_non-oss'}->{'url'} = "local://localhost:5081/srv/ftp/pub/opensuse/distribution/SL-10.1/non-oss-inst-source"; +$repository{'base_update'}->{'url'} = "local://localhost:5082/srv/ftp/pub/suse/update/10.1"; # Add a new selection: # $selection{'my-kde'} = "$selection{default} diff --git a/lib/distro-info/suse-10.2/settings.local.example b/lib/distro-info/suse-10.2/settings.local.example index bd5c529d..d0afaa7f 100644 --- a/lib/distro-info/suse-10.2/settings.local.example +++ b/lib/distro-info/suse-10.2/settings.local.example @@ -1,6 +1,7 @@ -# Use local installation sources. -$repository{base}->{url} = "ftp://localhost/pub/opensuse/distribution/10.2/repo/oss"; -$repository{base_update}->{url} = "ftp://localhost/pub/suse/update/10.2"; +# use local installation sources +$repository{'base'}->{'url'} = "local://localhost:5080/srv/ftp/pub/opensuse/distribution/10.2/repo/oss"; +$repository{'base_non-oss'}->{'url'} = "local://localhost:5081/srv/ftp/pub/opensuse/distribution/10.2/repo/non-oss"; +$repository{'base_update'}->{'url'} = "local://localhost:5082/srv/ftp/pub/suse/update/10.2"; # Add a new selection: # $selection{'my-kde'} = "$selection{default} diff --git a/lib/distro-info/suse-10.2_x86_64/settings.local.example b/lib/distro-info/suse-10.2_x86_64/settings.local.example index 58af4005..d0afaa7f 100644 --- a/lib/distro-info/suse-10.2_x86_64/settings.local.example +++ b/lib/distro-info/suse-10.2_x86_64/settings.local.example @@ -1,6 +1,7 @@ -# Use local installation sources. -# $repository{base}->{url} = "ftp://localhost/pub/opensuse/distribution/10.2/repo/oss"; -# $repository{base_update}->{url} = "ftp://localhost/pub/suse/update/10.2"; +# use local installation sources +$repository{'base'}->{'url'} = "local://localhost:5080/srv/ftp/pub/opensuse/distribution/10.2/repo/oss"; +$repository{'base_non-oss'}->{'url'} = "local://localhost:5081/srv/ftp/pub/opensuse/distribution/10.2/repo/non-oss"; +$repository{'base_update'}->{'url'} = "local://localhost:5082/srv/ftp/pub/suse/update/10.2"; # Add a new selection: # $selection{'my-kde'} = "$selection{default} -- cgit v1.2.3-55-g7522