aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2014-12-26 23:19:14 +0100
committerAngelo Naselli <anaselli@linux.it>2014-12-26 23:19:14 +0100
commitcdc32d5c533db208a894941e517df464da097b2f (patch)
treeffe1af3101aed6cf985f31b007c1d30cfb5a32cc
parent85c933f751ab236c28a3f5db92968a50e3073774 (diff)
downloadcolin-keep-cdc32d5c533db208a894941e517df464da097b2f.tar
colin-keep-cdc32d5c533db208a894941e517df464da097b2f.tar.gz
colin-keep-cdc32d5c533db208a894941e517df464da097b2f.tar.bz2
colin-keep-cdc32d5c533db208a894941e517df464da097b2f.tar.xz
colin-keep-cdc32d5c533db208a894941e517df464da097b2f.zip
added enable/disable/start/stop using dbus
-rw-r--r--lib/AdminPanel/Shared/Services.pm45
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/AdminPanel/Shared/Services.pm b/lib/AdminPanel/Shared/Services.pm
index 91284ef..3230e16 100644
--- a/lib/AdminPanel/Shared/Services.pm
+++ b/lib/AdminPanel/Shared/Services.pm
@@ -375,15 +375,16 @@ sub set_service {
$ENV{PATH} = "/usr/bin:/usr/sbin";
AdminPanel::Shared::RunProgram::rooted("", "/usr/sbin/chkconfig", $enable ? "--add" : "--del", $service);
} elsif ($self->_running_systemd() || $self->_has_systemd()) {
- # systemctl rejects any symlinked units. You have to enabled the real file
- if (-l "/usr/lib/systemd/system/$service.service") {
- my $name = readlink("/usr/lib/systemd/system/$service.service");
- $service = MDK::Common::File::basename($name);
- } else {
- $service = $service . ".service";
+ $service = $service . ".service";
+ my $dbus_object = $self->dbus_systemd1_object;
+ if ($enable) {
+ $dbus_object->EnableUnitFiles([$service], 0, 1);
}
- $ENV{PATH} = "/usr/bin:/usr/sbin";
- AdminPanel::Shared::RunProgram::rooted("", "/usr/bin/systemctl", $enable ? "enable" : "disable", $service);
+ else {
+ $dbus_object->DisableUnitFiles([$service], 0);
+ }
+ # reload local cache
+ $self->_systemd_services(1);
} else {
my $script = "/etc/rc.d/init.d/$service";
$ENV{PATH} = "/usr/bin:/usr/sbin";
@@ -397,15 +398,17 @@ sub set_service {
}
sub _run_action {
- my ($self, $service, $action, $do_not_block) = @_;
+ my ($self, $service, $action) = @_;
if ($self->_running_systemd()) {
- if ($do_not_block) {
- $ENV{PATH} = "/usr/bin:/usr/sbin";
- AdminPanel::Shared::RunProgram::rooted("", '/usr/bin/systemctl', '--no-block', $action, "$service.service");
+ my $object = $self->dbus_systemd1_object;
+ if ($action eq 'start') {
+ $object->StartUnit("$service.service", 'fail');
+ }
+ elsif ($action eq 'stop') {
+ $object->StopUnit("$service.service", 'fail');
}
else {
- $ENV{PATH} = "/usr/bin:/usr/sbin";
- AdminPanel::Shared::RunProgram::rooted("", '/usr/bin/systemctl', $action, "$service.service");
+ $object->RestartUnit("$service.service", 'fail');
}
} else {
$ENV{PATH} = "/usr/bin:/usr/sbin:/etc/rc.d/init.d/";
@@ -461,7 +464,7 @@ sub _systemd_services {
my ($self, $reload) = @_;
if ($reload) {
- $self->_serviceInfoInitialization();
+ $self->service_info($self->_serviceInfoInitialization());
}
my @services;
@@ -580,11 +583,11 @@ sub services {
}
-
+# if we loaded service info, then exists
sub _systemd_unit_exists {
my ($self, $name) = @_;
- # we test with -l as symlinks are not valid when the system is chrooted:
- -e "/usr/lib/systemd/system/$name.service" or -l "/usr/lib/systemd/system/$name.service";
+
+ return defined ($self->get_service_info($name));
}
#=============================================================
@@ -610,7 +613,7 @@ sub _systemd_unit_exists {
sub service_exists {
my ($self, $service) = @_;
- -x "/etc/rc.d/init.d/$service" or $self->_systemd_unit_exists($service);
+ $self->_systemd_unit_exists($service) or -x "/etc/rc.d/init.d/$service";
}
#=============================================================
@@ -752,8 +755,8 @@ sub is_service_running {
$self->service_exists($service) or return 0;
my $out;
if ($self->_running_systemd()) {
- $ENV{PATH} = "/usr/bin:/usr/sbin";
- $out = AdminPanel::Shared::RunProgram::rooted("", '/usr/bin/systemctl', '--quiet', 'is-active', "$service.service");
+ my $ser_info = $self->get_service_info($name);
+ $out = $ser_info->{active_state} eq 'active';
} else {
$ENV{PATH} = "/usr/bin:/usr/sbin";
$out = AdminPanel::Shared::RunProgram::rooted("", '/usr/sbin/service', $service, 'status');