From 9d5d79052688470ad40e73315ce9c79e5144e325 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sat, 1 Feb 2025 21:23:22 +0200 Subject: [PATCH] Fix to ensure systemd custom units are created in the correct directory --- init/init-lib.pl | 9 ++++++--- init/updateboot.pl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/init/init-lib.pl b/init/init-lib.pl index 341c613d2..f4a83981b 100644 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -2147,7 +2147,7 @@ foreach my $l (split(/\r?\n/, $out)) { # Also find unit files for units that may be disabled at boot and not running, # and so don't show up in systemctl list-units -my $root = &get_systemd_root(); +my $root = &get_systemd_root(undef, 1); opendir(UNITS, $root); push(@units, grep { !/\.wants$/ && !/^\./ && !-d "$root/$_" } readdir(UNITS)); closedir(UNITS); @@ -2452,14 +2452,14 @@ foreach my $s (&list_systemd_services(1)) { return 0; } -=head2 get_systemd_root([name]) +=head2 get_systemd_root([name], [packaged]) Returns the base directory for systemd unit config files =cut sub get_systemd_root { -my ($name) = @_; +my ($name, $packaged) = @_; # Default systemd paths my $systemd_local_conf = "/etc/systemd/system"; my $systemd_unit_dir1 = "/usr/lib/systemd/system"; @@ -2485,6 +2485,9 @@ if ($name) { } } } +# Always use /etc/systemd/system for locally created units +return $systemd_local_conf if (!$packaged && -d $systemd_local_conf); + # Debian prefers /lib/systemd/system if ($gconfig{'os_type'} eq 'debian-linux' && -d $systemd_unit_dir2) { diff --git a/init/updateboot.pl b/init/updateboot.pl index ce16f2499..2fcb8ec5c 100755 --- a/init/updateboot.pl +++ b/init/updateboot.pl @@ -20,7 +20,7 @@ if ($product) { quotemeta($product).".service 2>&1"); $status = &trim($status) if ($status); # Delete all possible service files - my $systemd_root = &get_systemd_root(); + my $systemd_root = &get_systemd_root(undef, 1); foreach my $p ( "/etc/systemd/system", "/usr/lib/systemd/system",