summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2020-09-16 12:12:32 +0100
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2020-09-16 12:12:32 +0100
commit8f7e1c4bb768a70935ed7047e50b6a6f198a2a0c (patch)
treec2e785c55147608a9b1f2496ec79cbedf151b7ba
parenteba60e9b55a8ab3f551f0160fa8e02e90f713c5e (diff)
downloaddrakx-8f7e1c4bb768a70935ed7047e50b6a6f198a2a0c.tar
drakx-8f7e1c4bb768a70935ed7047e50b6a6f198a2a0c.tar.gz
drakx-8f7e1c4bb768a70935ed7047e50b6a6f198a2a0c.tar.bz2
drakx-8f7e1c4bb768a70935ed7047e50b6a6f198a2a0c.tar.xz
drakx-8f7e1c4bb768a70935ed7047e50b6a6f198a2a0c.zip
Simplify and improve services::services().
This filters out static services that can't be enabled or disabled.
-rw-r--r--perl-install/services.pm61
1 files changed, 6 insertions, 55 deletions
diff --git a/perl-install/services.pm b/perl-install/services.pm
index a0b2df027..e2dd69580 100644
--- a/perl-install/services.pm
+++ b/perl-install/services.pm
@@ -377,42 +377,19 @@ sub xinetd_services() {
sub _systemd_services() {
local $ENV{LANGUAGE} = 'C';
my @services;
- my %loaded;
- # Running system using systemd
- log::explanations("Detected systemd running. Using systemctl introspection.");
- # even if systemd is not running, we can detect status of shorewell service which is not wanted by:
- my @opts = $::isInstall ? 'list-unit-files' : qw(--all --plain list-units);
- foreach (run_program::rooted_get_stdout($::prefix, '/bin/systemctl', '--no-legend', '--no-pager', '--full', @opts)) {
- my ($name, $type) = m!^(\S+)\.(service|socket|timer)\s+loaded!;
- ($name, $type) = m!^(\S+)\.(service|socket|timer)\s+enabled! if $::isInstall && !$name;
- my $unit_name = "$name.$type";
+ log::explanations("Detected systemd. Using systemctl introspection.");
+ foreach (run_program::rooted_get_stdout($::prefix, '/bin/systemctl', '--no-legend', '--no-pager', '--full', 'list-unit-files')) {
+ my ($name, $type) = m!^(\S+)\.(service|socket|timer)\s+(enabled|disabled|generated)!;
if ($name) {
+ my $unit_name = "$name.$type";
# We only look at non-template, non-linked service files in /lib
# We also check for any non-masked sysvinit files as these are
# also handled by systemd
if ($name !~ /.*\@$/g && (-e "$::prefix/lib/systemd/system/$unit_name" or -e "$::prefix/etc/rc.d/init.d/$name") && ! -l "$::prefix/lib/systemd/system/$unit_name") {
push @services, [ _list_name($name, $type), !!run_program::rooted($::prefix, '/bin/systemctl', '--quiet', 'is-enabled', "$unit_name") ];
- $loaded{$unit_name} = 1;
}
}
}
- # list-units will not list disabled units that can be enabled
- foreach (run_program::rooted_get_stdout($::prefix, '/bin/systemctl', '--no-legend', '--no-pager', '--full', 'list-unit-files')) {
- if (my ($name, $type) = m!^(\S+)\.(service|socket|timer)\s+disabled!) {
- my $unit_name = "$name.$type";
- # We only look at non-template, non-linked service files in /lib
- # We also check for any non-masked sysvinit files as these are
- # also handled by systemd
- if (!exists $loaded{$unit_name} && $name !~ /.*\@$/g && (-e "$::prefix/lib/systemd/system/$unit_name" or -e "$::prefix/etc/rc.d/init.d/$name") && ! -l "$::prefix/lib/systemd/system/$unit_name") {
- # Limit ourselves to "standard" targets which can be enabled
- my $wantedby = cat_("$::prefix/lib/systemd/system/$unit_name") =~ /^WantedBy=(graphical|multi-user|sockets|timers).target$/sm ? $1 : '';
- if ($wantedby) {
- push @services, [ _list_name($name, $type), 0 ];
- }
- }
- }
- }
-
@services;
}
@@ -426,28 +403,8 @@ sub _legacy_services() {
# as much as is practicable from the native systemd unit files and
# combine that with information from chkconfig regarding legacy sysvinit
# scripts (which systemd will parse and include when running)
- log::explanations("Detected systemd installed. Using fake service+chkconfig introspection.");
- foreach (glob("$::prefix/lib/systemd/system/*.{service,socket,timer}")) {
- my ($name, $type) = m!([^/]*)\.(service|socket|timer)$!;
- my $unit_name = "$name.$type";
-
- # We only look at non-template, non-symlinked service files
- if ($name !~ /.*\@$/g && ! -l $_) {
- # Limit ourselves to "standard" targets
- my $wantedby = cat_($_) =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : '';
- if ($wantedby) {
- # Exclude if enabled statically
- # Note DO NOT use -e when testing for files that could
- # be symbolic links as this will fail under a chroot
- # setup where -e will fail if the symlink target does
- # exist which is typically the case when viewed outside
- # of the chroot.
- if (!-l "$::prefix/lib/systemd/system/$wantedby.target.wants/$unit_name") {
- push @services, [ _list_name($name, $type), !!-l "$::prefix/etc/systemd/system/$wantedby.target.wants/$unit_name" ];
- }
- }
- }
- }
+ log::explanations("Detected systemd installed. Using systemctl+chkconfig introspection.");
+ @services = _systemd_services();
} else {
log::explanations("Could not detect systemd. Using chkconfig service introspection.");
}
@@ -486,12 +443,6 @@ sub services() {
@services = _systemd_services();
} else {
@services = _legacy_services();
- # list shorewall and the like which are not "wantedBy":
- if ($::isInstall) {
- # prevent listing some services twice:
- my @found = map { $_->[0] } @services;
- push @services, grep { !member($_->[0], @found) } _systemd_services();
- }
}
my @l = xinetd_services();