mirror of https://github.com/schoebel/mars
marsadm: only work on enabled systemd units
This commit is contained in:
parent
1eecf11d96
commit
82798296a8
|
@ -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(@_);
|
||||
|
|
Loading…
Reference in New Issue