Skip to content

Commit

Permalink
#IP-1332 Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxwin committed May 5, 2015
1 parent 704f38e commit 087ed05
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -97,6 +97,7 @@ YOUTRACK
Fixed #IP-1323: Invalid query result column used in change_domain_status() function
Fixed #IP-1327: Unable to add subdomain (subals) - An error occurred while reading flags on ...
Fixed #IP-1330: Proftpd - Unable to connect to i-MSCP database
Fixed #IP-1332: nginx / nginx-light package configuration fail which result to i-MSCP installation failure

------------------------------------------------------------------------------------------------------------------------
1.2.2
Expand Down
81 changes: 57 additions & 24 deletions autoinstaller/Adapter/DebianAdapter.pm
Expand Up @@ -156,24 +156,6 @@ sub installPackages
);
return $rs if $rs;

# Prevent the package manager to start some services itself using the policy layer interface.
# Apache2: This prevents failures such as when nginx is installed after Apache2 which is already listening on port 80...
# Bind9: This avoid error when resolvconf is not configured yet
my $file = iMSCP::File->new( filename => '/usr/sbin/policy-rc.d' );
$rs = $file->set(<<EOF);
#/bin/sh
initscript=\$1
action=\$2
if [ "\$action" = "start" ] && { [ "\$initscript" = "apache2" ] || [ "\$initscript" = "bind9" ] ; } then
exit 101;
fi
exit 0
EOF

$rs ||= $file->save();
$rs ||= $file->mode(0755);
return $rs if $rs;

my $preseed = iMSCP::Getopt->preseed;

for my $packages($self->{'packagesToInstall'}, $self->{'packagesToInstallDelayed'}) {
Expand Down Expand Up @@ -203,10 +185,6 @@ EOF
}
}

# Delete '/usr/sbin/policy-rc.d file
$rs = $file->delFile();
return $rs if $rs;

$self->{'eventManager'}->trigger('afterInstallPackages');
}

Expand Down Expand Up @@ -279,6 +257,8 @@ sub uninstallPackages

sub postBuild
{
my $self = shift;

# Needed to fix #IP-1246
if(iMSCP::ProgramFinder::find('php5dismod')) {
for (
Expand Down Expand Up @@ -311,7 +291,7 @@ sub postBuild
}
}

0;
$self->_setupInitScriptPolicyLayer('disable');
}

=back
Expand Down Expand Up @@ -350,11 +330,64 @@ sub _init
$self->{'packagesToPreUninstall'} = [];
$self->{'packagesToUninstall'} = [];

$self->_updateAptSourceList() and fatal('Unable to configure APT packages manager') unless $main::skippackages;
unless($main::skippackages) {
($self->_setupInitScriptPolicyLayer('enable') == 0 ) or die('Unable to setup initscriptpolicy layer');
($self->_updateAptSourceList() == 0) or die('Unable to configure APT packages manager');
}

$self;
}

=item _setupInitScriptPolicyLayer($action)
Enable or disable initscript policy layer
See https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt
See man invoke-rc.d
param string $action Action ( enable|disable )
Return int 0 on success, other on failure
=cut

sub _setupInitScriptPolicyLayer
{
my $action = $_[1];
my $rs = 0;

if($action eq 'enable') {
# Prevents invoke-rc.d ( which is invoked by package maintainer scripts ) to start some services
# apache2 and nginx: This prevents failures such as "bind() to 0.0.0.0:80 failed (98: Address already in use"
# bind9: This avoid error when resolvconf is not configured yet
my $file = iMSCP::File->new( filename => '/usr/sbin/policy-rc.d' );
my $rs = $file->set(<<EOF);
#/bin/sh
initscript=\$1
action=\$2
if [ "\$action" = "start" ] || [ "\$action" = "restart" ]; then
for i in apache2 bind9 nginx; do
if [ "\$initscript" = "\$i" ]; then
exit 101;
fi
done
fi
EOF

$rs ||= $file->save();
$rs ||= $file->mode(0755);
} elsif($action eq 'disable') {
if(-f '/usr/sbin/policy-rc.d') {
$rs = iMSCP::File->new( filename => '/usr/sbin/policy-rc.d' )->delFile();
}
} else {
error('Unknown action');
$rs = 1;
}

$rs;
}

=item _buildPackageList()
Build lists of Debian packages to uninstall and install
Expand Down
5 changes: 4 additions & 1 deletion autoinstaller/Adapter/UbuntuAdapter.pm
Expand Up @@ -85,7 +85,10 @@ sub _init
$self->{'packagesToPreUninstall'} = [];
$self->{'packagesToUninstall'} = [];

$self->_updateAptSourceList() and fatal('Unable to configure APT packages manager') unless $main::skippackages;
unless($main::skippackages) {
($self->_setupInitScriptPolicyLayer('enable') == 0) or die('Unable to setup initscript policy layer');
($self->_updateAptSourceList() == 0) or die('Unable to configure APT packages manager');
}

$self;
}
Expand Down

0 comments on commit 087ed05

Please sign in to comment.