diff options
author | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2020-09-15 09:19:23 +0100 |
---|---|---|
committer | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2020-09-15 09:19:23 +0100 |
commit | 42ae062bd55b9d39324e75573a749b68337f0f1d (patch) | |
tree | ea2e7354a4dc72e95cf44fae9dc437c2c3fdd37f /perl-install/services.pm | |
parent | 295c9a3d66d99893f79c763c78ee1a43e7fc113e (diff) | |
download | drakx-42ae062bd55b9d39324e75573a749b68337f0f1d.tar drakx-42ae062bd55b9d39324e75573a749b68337f0f1d.tar.gz drakx-42ae062bd55b9d39324e75573a749b68337f0f1d.tar.bz2 drakx-42ae062bd55b9d39324e75573a749b68337f0f1d.tar.xz drakx-42ae062bd55b9d39324e75573a749b68337f0f1d.zip |
Support systemd sockets and timers in service manipulation routines.
Diffstat (limited to 'perl-install/services.pm')
-rw-r--r-- | perl-install/services.pm | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/perl-install/services.pm b/perl-install/services.pm index 1aab437a1..95e068770 100644 --- a/perl-install/services.pm +++ b/perl-install/services.pm @@ -13,6 +13,17 @@ use run_program; use File::Basename; +sub _unit_name { + my ($service) = @_; + return $service if $service =~ /\.(service|socket|timer)$/; + "$service.service"; +} + +sub _base_name { + my ($service) = @_; + $service =~ s/\.(service|socket|timer)$//; +} + sub description { my %services = ( acpid => N_("Listen and dispatch ACPI events from the kernel"), @@ -125,11 +136,11 @@ xfs => N_("Starts the X Font Server."), xinetd => N_("Starts other deamons on demand."), ); my ($name) = @_; - my $s = $services{$name}; + my $s = $services{_base_name($name)}; if ($s) { $s = translate($s); } else { - my $file = "$::prefix/usr/lib/systemd/system/$name.service"; + my $file = "$::prefix/usr/lib/systemd/system/" . _unit_name($name); if (-e $file) { $s = cat_($file); $s = $s =~ /^Description=(.*)/mg ? $1 : ''; @@ -297,13 +308,12 @@ sub _set_service { if (member($service, @xinetd_services)) { run_program::rooted($::prefix, "chkconfig", "--no-reload", $enable ? "--add" : "--del", $service); # Probably still a bug here as xinet support in chkconfig shells out to /sbin/service.... } elsif (running_systemd() || has_systemd()) { + my $unit_name = _unit_name($service); # systemctl rejects any symlinked units. You have to enabled the real file - if (-l "/lib/systemd/system/$service.service") { - $service = basename(readlink("/lib/systemd/system/$service.service")); - } else { - $service = $service . ".service"; + if (-l "/lib/systemd/system/$unit_name") { + $unit_name = basename(readlink("/lib/systemd/system/$unit_name")); } - run_program::rooted($::prefix, "/bin/systemctl", $enable ? "enable" : "disable", "--no-reload", $service); + run_program::rooted($::prefix, "/bin/systemctl", $enable ? "enable" : "disable", "--no-reload", $unit_name); } else { my $script = "/etc/rc.d/init.d/$service"; run_program::rooted($::prefix, "chkconfig", "--no-reload", $enable ? "--add" : "--del", $service); @@ -317,7 +327,7 @@ sub _set_service { sub _run_action { my ($service, $action) = @_; if (running_systemd()) { - run_program::rooted($::prefix, '/bin/systemctl', '--no-block', $action, "$service.service"); + run_program::rooted($::prefix, '/bin/systemctl', '--no-block', $action, _unit_name($service)); } else { run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", $action); } @@ -487,8 +497,9 @@ sub services() { sub systemd_unit_exists { my ($name) = @_; + my $unit_name = _unit_name($name); # we test with -l as symlinks are not valid when the system is chrooted: - -e "$::prefix/lib/systemd/system/$name.service" or -l "$::prefix/lib/systemd/system/$name.service"; + -e "$::prefix/lib/systemd/system/$unit_name" or -l "$::prefix/lib/systemd/system/$unit_name"; } sub service_exists { @@ -536,7 +547,7 @@ sub is_service_running ($) { # Exit silently if the service is not installed service_exists($service) or return 1; if (running_systemd()) { - run_program::rooted($::prefix, '/bin/systemctl', '--quiet', 'is-active', "$service.service"); + run_program::rooted($::prefix, '/bin/systemctl', '--quiet', 'is-active', _unit_name($service)); } else { run_program::rooted($::prefix, '/sbin/service', $service, 'status'); } |