Fix to ensure systemd custom units are created in the correct directory

This commit is contained in:
Ilia Ross
2025-02-01 21:23:22 +02:00
parent 433c4151fe
commit 9d5d790526
2 changed files with 7 additions and 4 deletions

View File

@ -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) {

View File

@ -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",