marsadm: only work on enabled systemd units

This commit is contained in:
Thomas Schoebel-Theuer 2019-01-29 08:35:12 +01:00
parent 1eecf11d96
commit 82798296a8
1 changed files with 22 additions and 0 deletions

View File

@ -342,8 +342,24 @@ sub instantiate_systemd_unit {
return (1, $outfile);
}
sub systemd_enabled {
my ($unit_list) = @_;
foreach my $unit (split(/ +/, $unit_list)) {
my $check_cmd = "$systemctl is-enabled \"$unit\" > /dev/null 2>&1";
my $status = system($check_cmd);
if ($status) {
lprint "systemd unit '$unit' is not existing or not enabled.\n";
return $status;
}
}
return 0;
}
sub _systemd_op {
my ($op, $unit) = @_;
if (systemd_enabled($unit)) {
return;
}
my $ctl_cmd = "$systemctl $op \"$unit\"";
if (system("$systemctl cat '$unit' > /dev/null 2>&1")) {
lwarn "systemd unit $unit does not exist.\n";
@ -378,6 +394,9 @@ sub systemd_activate {
lprint "Nothing to (de)activate: $unit_path does not exist\n" if $verbose;
return;
}
if (systemd_enabled($unit)) {
return;
}
my $ctl_cmd = "$systemctl show \"$unit\"";
system($ctl_cmd) if $verbose;
my $op = "show";
@ -503,6 +522,9 @@ sub _systemd_trigger {
system("$systemctl start '$needed_unit'");
}
}
if (systemd_enabled($needed_unit)) {
return;
}
my $trigger = "$mars/userspace/systemd-trigger";
lprint "Triggering '$trigger' for '$cmd'\n"if $verbose;
system("touch $trigger") and systemd_trigger(@_);