Skip to content

Commit

Permalink
Fixed: Could not remove service (iMSCP::Service)
Browse files Browse the repository at this point in the history
CS fixes
  • Loading branch information
nuxwin committed Oct 20, 2016
1 parent 25e170e commit 308c5a4
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Expand Up @@ -4,8 +4,11 @@
Git 1.3.x
------------------------------------------------------------------------------------------------------------------------

BACKEND
Fixed: Could not remove service (iMSCP::Service)

SERVERS
Fixed: TLSProtocol directive not allowed in global context (ProFTPD)
Fixed: `TLSProtocol' directive not allowed in global context (ProFTPD)

------------------------------------------------------------------------------------------------------------------------
1.3.6
Expand Down
12 changes: 6 additions & 6 deletions engine/PerlLib/iMSCP/Provider/Service/Debian/Systemd.pm
Expand Up @@ -32,15 +32,15 @@ use parent qw/ iMSCP::Provider::Service::Systemd iMSCP::Provider::Service::Debia

# Commands used in that package
my %COMMANDS = (
dpkg => [ '/usr/bin/dpkg' ],
systemctl => [ '/bin/systemctl' ]
dpkg => '/usr/bin/dpkg',
%iMSCP::Provider::Service::Systemd::COMMANDS
);

# Enable compatibility mode if systemd version is lower than version 204-3
my $SYSTEMCTL_COMPAT_MODE = lazy
{
__PACKAGE__->_exec(
"@{$COMMANDS{'dpkg'}} --compare-versions \$(dpkg-query -W -f='\${Version}' systemd) lt 204-3"
"$COMMANDS{'dpkg'} --compare-versions \$(dpkg-query -W -f='\${Version}' systemd) lt 204-3"
) == 0;
};

Expand Down Expand Up @@ -114,7 +114,7 @@ sub enable
# of changes.
if ($self->_isSysvinit( $unit )) {
return $self->iMSCP::Provider::Service::Debian::Sysvinit::enable( $unit )
&& $self->_exec( @{$COMMANDS{'systemctl'}}, 'daemon-reload' ) == 0
&& $self->_exec( $COMMANDS{'systemctl'}, '--system', 'daemon-reload' ) == 0
}

return 1;
Expand Down Expand Up @@ -157,7 +157,7 @@ sub disable
# of changes.
if ($self->_isSysvinit( $unit )) {
return $self->iMSCP::Provider::Service::Debian::Sysvinit::disable( $unit )
&& $self->_exec( @{$COMMANDS{'systemctl'}}, 'daemon-reload' ) == 0;
&& $self->_exec( $COMMANDS{'systemctl'}, '--system', 'daemon-reload' ) == 0;
}

return 1;
Expand Down Expand Up @@ -189,7 +189,7 @@ sub remove
# Remove the underlying sysvinit script if any and make systemd aware of changes
if ($self->_isSysvinit( $unit )) {
return $self->iMSCP::Provider::Service::Debian::Sysvinit::remove( $unit )
&& $self->_exec( @{$COMMANDS{'systemctl'}}, 'daemon-reload' ) == 0;
&& $self->_exec( $COMMANDS{'systemctl'}, '--system', 'daemon-reload' ) == 0;
}

1;
Expand Down
2 changes: 1 addition & 1 deletion engine/PerlLib/iMSCP/Provider/Service/Debian/Sysvinit.pm
Expand Up @@ -57,7 +57,7 @@ my $SYSVRC_COMPAT_MODE = lazy
=item isEnabled($service)
Does the given service is enabled?
Is the given service enabled?
Param string $service Service name
Return bool TRUE if the given service is enabled, FALSE otherwise
Expand Down
24 changes: 12 additions & 12 deletions engine/PerlLib/iMSCP/Provider/Service/Systemd.pm
Expand Up @@ -31,7 +31,7 @@ use parent 'iMSCP::Provider::Service::Sysvinit';

# Commands used in that package
my %COMMANDS = (
systemctl => [ '/bin/systemctl', '--system' ]
systemctl => '/bin/systemctl'
);

# Paths in which service units must be searched
Expand All @@ -57,7 +57,7 @@ my @UNITFILEPATHS = (
=item isEnabled($unit)
Is the given service/socket unit is enabled?
Is the given service/socket unit enabled?
Param string $unit Unit name
Return bool TRUE if the given unit is enabled, FALSE otherwise
Expand All @@ -70,7 +70,7 @@ sub isEnabled

defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.(?:service|socket)$/;
$self->_exec( @{$COMMANDS{'systemctl'}}, '--quiet', 'is-enabled', $unit ) == 0;
$self->_exec( $COMMANDS{'systemctl'}, '--system', '--quiet', 'is-enabled', $unit ) == 0;
}

=item enable($unit)
Expand All @@ -88,7 +88,7 @@ sub enable

defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.(?:service|socket)$/;
$self->_exec( @{$COMMANDS{'systemctl'}}, '--force', '--quiet', 'enable', $unit ) == 0;
$self->_exec( $COMMANDS{'systemctl'}, '--system', '--force', '--quiet', 'enable', $unit ) == 0;
}

=item disable($unit)
Expand All @@ -106,7 +106,7 @@ sub disable

defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.(?:service|socket)$/;
$self->_exec( @{$COMMANDS{'systemctl'}}, '--quiet', 'disable', $unit ) == 0;
$self->_exec( $COMMANDS{'systemctl'}, '--system', '--quiet', 'disable', $unit ) == 0;
}

=item remove($unit)
Expand All @@ -132,7 +132,7 @@ sub remove
return 0 if iMSCP::File->new( filename => $unitFilePath )->delFile();
}

$self->_exec( @{$COMMANDS{'systemctl'}}, 'daemon-reload' ) == 0;
$self->_exec( $COMMANDS{'systemctl'}, '--system', 'daemon-reload' ) == 0;
}

=item start($unit)
Expand All @@ -150,7 +150,7 @@ sub start

defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.(?:service|socket)$/;
$self->_exec( @{$COMMANDS{'systemctl'}}, 'start', $unit ) == 0;
$self->_exec( $COMMANDS{'systemctl'}, '--system', 'start', $unit ) == 0;
}

=item stop($unit)
Expand All @@ -169,7 +169,7 @@ sub stop
defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.(?:service|socket)$/;
return 1 unless $self->isRunning( $unit );
$self->_exec( @{$COMMANDS{'systemctl'}}, 'stop', $unit ) == 0;
$self->_exec( $COMMANDS{'systemctl'}, '--system', 'stop', $unit ) == 0;
}

=item restart($unit)
Expand All @@ -187,8 +187,8 @@ sub restart

defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.(?:service|socket)$/;
return $self->_exec( @{$COMMANDS{'systemctl'}}, 'restart', $unit ) == 0 if $self->isRunning( $unit );
$self->_exec( @{$COMMANDS{'systemctl'}}, 'start', $unit ) == 0;
return $self->_exec( $COMMANDS{'systemctl'}, 'restart', $unit ) == 0 if $self->isRunning( $unit );
$self->_exec( $COMMANDS{'systemctl'}, '--system', 'start', $unit ) == 0;
}

=item reload($service)
Expand All @@ -208,7 +208,7 @@ sub reload

defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.service$/;
return $self->_exec( @{$COMMANDS{'systemctl'}}, 'reload', $unit ) == 0 if $self->isRunning( $unit );
return $self->_exec( $COMMANDS{'systemctl'}, '--system', 'reload', $unit ) == 0 if $self->isRunning( $unit );
$self->start( $unit );
}

Expand All @@ -227,7 +227,7 @@ sub isRunning

defined $unit or die( 'parameter $unit is not defined' );
$unit .= '.service' unless $unit =~ /\.(?:service|socket)$/;
$self->_exec( @{$COMMANDS{'systemctl'}}, 'is-active', $unit ) == 0;
$self->_exec( $COMMANDS{'systemctl'}, '--system', 'is-active', $unit ) == 0;
}

=item getUnitFilePath($unit)
Expand Down
4 changes: 2 additions & 2 deletions engine/PerlLib/iMSCP/Provider/Service/Sysvinit.pm
Expand Up @@ -77,7 +77,7 @@ sub getInstance

=item isEnabled($service)
Does the given service is enabled?
Is the given service enabled?
Param string $service Service name
Return bool TRUE
Expand Down Expand Up @@ -332,7 +332,7 @@ sub _exec
my (undef, @command) = @_;

my $ret = execute( [ @command ], \ my $stdout, \ my $stderr );
debug($stdout) if $stdout;
debug( $stdout ) if $stdout;
error( $stderr ) if $ret && $stderr;
$ret;
}
Expand Down
4 changes: 2 additions & 2 deletions engine/PerlLib/iMSCP/Provider/Service/Upstart.pm
Expand Up @@ -66,7 +66,7 @@ my @JOBFILEPATHS = ( '/etc/init' );
=item isEnabled($job)
Is the given job is enabled?
Is the given job enabled?
Return bool TRUE if the given job is enabled, FALSE otherwise
Expand Down Expand Up @@ -293,7 +293,7 @@ sub isRunning
$self->SUPER::isRunning( $job );
}

=item getJobFilePath($job [ , $jobFileType = 'conf' ])
=item getJobFilePath($job [, $jobFileType = 'conf' ])
Get full path of the job configuration file or job override file which belongs to the given job
Expand Down
6 changes: 3 additions & 3 deletions engine/PerlLib/iMSCP/Service.pm
Expand Up @@ -137,16 +137,16 @@ sub remove
$self->{'provider'}->remove( $service ) or die($self->_getLastError() );

unless($init eq 'sysvinit') {
my $provider = $self->getProvider( $_ );

if($init eq 'upstart') {
my $provider = $self->getProvider( 'systemd' );
for(qw / service socket/) {
my $unitFilePath = eval { $self->getUnitFilePath( "$service.$_" ); };
my $unitFilePath = eval { $provider->getUnitFilePath( "$service.$_" ); };
if (defined $unitFilePath) {
iMSCP::File->new( filename => $unitFilePath )->delFile() == 0 or die( $self->_getLastError() );
}
}
} else {
my $provider = $self->getProvider( 'upstart' );
for (qw / conf override /) {
my $jobfilePath = eval { $provider->getJobFilePath( $service, $_ ); };
if (defined $jobfilePath) {
Expand Down

0 comments on commit 308c5a4

Please sign in to comment.