Skip to content

Commit

Permalink
Fixed: Init system detection - Handle case where many init systems ar…
Browse files Browse the repository at this point in the history
…e installed

Fixed: Make iMSCP::Service::Systemd service provider backward compatible
Renamed iMSCP::Service::Init to iMSCP::Service:Sysvinit
Small fixes +++
  • Loading branch information
nuxwin committed Mar 20, 2015
1 parent 579f115 commit f93e95b
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 55 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG
Expand Up @@ -5,10 +5,10 @@ Git 1.2.x
------------------------------------------------------------------------------------------------------------------------

BACKEND
Added: Init, Upstart and Systemd service providers
Added: SysVinit, Upstart and Systemd service providers
Added: Custom DNS module ( Modules::CustomDNS )
Fixed: Any task which belongs to the custom DNS records layer must not involve HTTPD configuration change
Fixed: Bind9 must not be restarted each time a DNS zone is updated. A simple reload should be sufficient
Fixed: Bind9 must not be restarted each time a DNS zone is updated. A simple reload is sufficient
Fixed: Some errors are not trapped

CONFIGS
Expand All @@ -19,7 +19,7 @@ CONFIGS
DAEMON
Added: End child syslog message
Fixed: warning: ignoring return value of ‘chdir’... ( daemon_init.c )
Fixed: Avoid useless fork and wait by using execl() instead of system() ( lr_syntax.c )
Fixed: Avoid useless 'fork' and 'wait' by using execl() instead of system() ( lr_syntax.c )
Updated: Version to 1.2.3

DATABASE
Expand Down Expand Up @@ -47,21 +47,21 @@ INSTALLER

PLUGINS
Added: iMSCP_Plugin::getConfigPrev() and iMSCP_Plugin::getConfigPrevParam() methods
Added: require_api info field ( field which allows the plugins to define the required i-MSCP plugin API )
Added: require_api info field ( field which allows the plugins to define the required i-MSCP plugin API version )
Changed: info, config and config_prev fields are now automatically decoded and set as plugin properties ( backend )
Fixed: Force reload of newest plugin info file ( iMSCP_Plugin::getInfo() )
Fixed: Force reload of newest plugin configuration file ( iMSCP_Plugin::getConfigFromFile() )
Fixed: Opcode cache is not correctly resetted on plugin list update
Updated: API to version 1.0.0

SKELETON
Removed: Link to the panel in default index.html files ( Panel must not be publicly exposed )
Removed: Link to the panel in default index.html file ( Panel must not be publicly exposed )
Fixed: Wrong link for favicon in error pages

SERVICES
Added: Log summary message on TLS handshake completion ( Postfix )
Fixed: Apache access.log files are put in wrong directory ( vlogger )
Fixed: Disable warnings about missing SPF DNS record ( As per RFC 7208, SPF DNS record is deprecated ) ( Bind9 )
Fixed: Disable warnings about missing SPF DNS record ( As per RFC 7208, SPF DNS record is deprecated - Bind9 )

YOUTRACK
Fixed #IP-1275: Apache access logs are created in /<domain.tld>
Expand Down
53 changes: 31 additions & 22 deletions autoinstaller/Functions.pm
Expand Up @@ -387,44 +387,53 @@ sub _showUpdateNotices
my $imscpVersion = $main::imscpOldConfig{'Version'};
my $notices = '';

my @noticeFiles = iMSCP::Dir->new( dirname => $noticesDir )->getFiles();
unless($imscpVersion =~ /git/i) {
my @noticeFiles = iMSCP::Dir->new( dirname => $noticesDir )->getFiles();

if(@noticeFiles) {
@noticeFiles = reverse sort @noticeFiles;
if(@noticeFiles) {
@noticeFiles = reverse sort @noticeFiles;

for my $noticeFile(@noticeFiles) {
(my $noticeVersion = $noticeFile) =~ s/\.txt$//;
for my $noticeFile(@noticeFiles) {
(my $noticeVersion = $noticeFile) =~ s/\.txt$//;

# If Git version is detected, show all notices since we don't know the target version, else show only the
# relevant notices.
if($imscpVersion ~~ /git/i || version->parse("v$imscpVersion") < version->parse("v$noticeVersion")) {
my $noticeBody = iMSCP::File->new( filename => "$noticesDir/$noticeFile" )->get();
unless(defined $noticeBody) {
error("Unable to read $noticesDir/$noticeFile file");
return 1;
}
if(version->parse("v$imscpVersion") < version->parse("v$noticeVersion")) {
my $noticeBody = iMSCP::File->new( filename => "$noticesDir/$noticeFile" )->get();
unless(defined $noticeBody) {
error("Unable to read $noticesDir/$noticeFile file");
return 1;
}

$notices .= "\n$noticeBody";
$notices .= "\n$noticeBody";
}
}
}
} else {
$notices = <<EOF;
if($notices ne '') {
$dialog->set('yes-label', 'Continue');
$dialog->set('no-label', 'Abort');
my $rs = $dialog->yesno(<<EOF);
The installer detected that you're using the \\ZbGit\\ZB version of i-MSCP. Before continue, be sure to have read the errata file:
\\Zbhttps://github.com/i-MSCP/imscp/blob/1.2.x/docs/1.2.x_errata.md\\ZB
Be aware that the Git version of i-MSCP can be unstable and that no support is provided for it.
EOF
}

unless($notices eq '') {
$dialog->set('yes-label', 'Continue');
$dialog->set('no-label', 'Abort');
my $rs = $dialog->yesno(<<EOF);
Please read carefully before continue.
\\ZbNote:\\ZB Use the \\ZbPage Down\\ZB key from your keyboard to scroll down.
$notices
You can now either continue the update or abort if needed.
You can now either continue or abort if needed.
\\Zbi-MSCP Team\\ZB
EOF

$dialog->resetLabels();
return 50 if $rs;
}
$dialog->resetLabels();
return 50 if $rs;
}

0;
Expand Down
16 changes: 7 additions & 9 deletions engine/PerlLib/iMSCP/Execute.pm
Expand Up @@ -58,7 +58,7 @@ our @EXPORT = qw/execute escapeShell getExitCode/;
Param string $command Ccommand to execute
Param string \$stdout OPTIONAL Command stdout
Param string \$stderr OPTIONAL Command stderr
Return int External command exit code
Return int External command exit code or die on failure
=cut

Expand Down Expand Up @@ -89,8 +89,7 @@ sub execute($;$$)
$$stderr = capture_stderr { system($command); };
chomp($stderr);
} else {
fatal("Unable to execute command: $!") if system($command) == -1;
return getExitCode($?);
die("Unable to execute command: $!") if system($command) == -1;
}

getExitCode();
Expand Down Expand Up @@ -119,7 +118,7 @@ sub escapeShell($)
Return human exit code
Param int $exitValue Raw exit code (default to $?)
Return int exit code
Return int exit code or die on failure
=cut

Expand All @@ -128,12 +127,11 @@ sub getExitCode(;$)
my $exitValue = $_[0] // $?;

if ($exitValue == -1) {
error("Failed to execute external command: $!");
die("Failed to execute external command: $!");
} elsif ($exitValue & 127) {
error(''.
(
sprintf "External command died with signal %d, %s coredump",
($exitValue & 127), ($? & 128) ? 'with' : 'without'
die(
sprintf(
"External command died with signal %d, %s coredump", ($exitValue & 127), ($? & 128) ? 'with' : 'without'
)
);
} else {
Expand Down
68 changes: 58 additions & 10 deletions engine/PerlLib/iMSCP/Service.pm
Expand Up @@ -26,10 +26,10 @@ package iMSCP::Service;
use strict;
use warnings;
use iMSCP::Execute;
use iMSCP::ProgramFinder;

use parent 'Common::SingletonClass';

my $initSystem = _detectInitSystem();

=head1 DESCRIPTION
Package providing a set of functions for service management.
Expand Down Expand Up @@ -123,30 +123,43 @@ sub status
$self->{'provider'}->status($serviceName, $pattern);
}

=item isSysvinit()
Does sysvinit is used as init system?
Return bool TRUE if sysvinit is used as init system, FALSE otherwise
=cut

sub isSysvinit
{
($initSystem eq 'sysvinit');
}

=item isUpstart()
Does upstart is used as init system?
Return TRUE if upstart is used as init system, FALSE otherwise
Return bool TRUE if upstart is used as init system, FALSE otherwise
=cut

sub isUpstart
{
iMSCP::ProgramFinder::find('initctl');
($initSystem eq 'upstart');
}

=item isSystemd()
Does systemd is used as init system?
Return TRUE if systemd is used as init system, FALSE otherwise
Return bool TRUE if systemd is used as init system, FALSE otherwise
=cut

sub isSystemd
{
iMSCP::ProgramFinder::find('systemctl');
($initSystem eq 'systemd');
}

=back
Expand All @@ -167,20 +180,55 @@ sub _init
{
my $self = $_[0];

if(isSystemd()) {
if($self->isSystemd()) {
require iMSCP::Service::Systemd;
$self->{'provider'} = iMSCP::Service::Systemd->getInstance();
} elsif(isUpstart()) {
} elsif($self->isUpstart()) {
require iMSCP::Service::Upstart;
$self->{'provider'} = iMSCP::Service::Upstart->getInstance();
} else {
require iMSCP::Service::Init;
$self->{'provider'} = iMSCP::Service::Init->getInstance();
require iMSCP::Service::Sysvinit;
$self->{'provider'} = iMSCP::Service::Sysvinit->getInstance();
}

$self;
}

=item _detectInitSystem()
Detect init system in use
Return string init system in use
=cut

sub _detectInitSystem
{
my $initSystem = 'sysvinit';

my %initSystems = (
upstart => { command => '/sbin/init --version', regexp => qr/upstart/ },
systemd => { command => 'systemctl', regexp => qr/-\.mount/ }
);

local $@;

for(keys %initSystems) {
eval {
my ($stdout, $stderr);
execute($initSystems{$_}->{'command'}, \$stdout, \$stderr);

if($stdout =~ /$initSystems{$_}->{'regexp'}/) {
$initSystem = $_;
}
};

last if $initSystem ne 'sysvinit';
}

$initSystem;
}

=back
=head1 AUTHOR
Expand Down
12 changes: 6 additions & 6 deletions engine/PerlLib/iMSCP/Service/Systemd.pm
Expand Up @@ -26,7 +26,7 @@ package iMSCP::Service::Systemd;
use strict;
use warnings;
use iMSCP::Execute;
use parent 'iMSCP::Service::Init';
use parent 'iMSCP::Service::Sysvinit';

my $commands = {
systemctl => 'systemctl'
Expand All @@ -53,7 +53,7 @@ sub start
{
my ($self, $serviceName) = @_;

$self->_runCommand("$commands->{'systemctl'} start $serviceName");
$self->_runCommand("$commands->{'systemctl'} start $serviceName.service");
$self->status($serviceName);
}

Expand All @@ -70,7 +70,7 @@ sub stop
{
my ($self, $serviceName) = @_;

$self->_runCommand("$commands->{'systemctl'} stop $serviceName");
$self->_runCommand("$commands->{'systemctl'} stop $serviceName.service");
! $self->status($serviceName);
}

Expand All @@ -87,7 +87,7 @@ sub restart
{
my ($self, $serviceName) = @_;

$self->_runCommand("$commands->{'systemctl'} restart $serviceName");
$self->_runCommand("$commands->{'systemctl'} restart $serviceName.service");
$self->status($serviceName);
}

Expand All @@ -107,7 +107,7 @@ sub reload
if($self->status($serviceName)) {
$self->start($serviceName);
} else {
$self->_runCommand("$commands->{'systemctl'} reload $serviceName");
$self->_runCommand("$commands->{'systemctl'} reload $serviceName.service");
$self->status($serviceName);
}
}
Expand All @@ -126,7 +126,7 @@ sub status
my ($self, $serviceName) = @_;

my ($stdout, $stderr);
execute("$commands->{'systemctl'} is-active $serviceName", \$stdout, \$stderr);
execute("$commands->{'systemctl'} is-active $serviceName.service", \$stdout, \$stderr);
}

=back
Expand Down
Expand Up @@ -21,7 +21,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

package iMSCP::Service::Init;
package iMSCP::Service::Sysvinit;

use strict;
use warnings;
Expand Down
2 changes: 1 addition & 1 deletion engine/PerlLib/iMSCP/Service/Upstart.pm
Expand Up @@ -26,7 +26,7 @@ package iMSCP::Service::Upstart;
use strict;
use warnings;
use iMSCP::Execute;
use parent 'iMSCP::Service::Init';
use parent 'iMSCP::Service::Sysvinit';

my $commands = {
start => 'start',
Expand Down

0 comments on commit f93e95b

Please sign in to comment.