mirror of
https://git.proxmox.com/git/pve-common
synced 2025-04-28 18:53:18 +00:00
add PVE::Systemd::is_unit_active
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
c6ec71d846
commit
68b234f35e
@ -167,6 +167,23 @@ sub wait_for_unit_removed($;$) {
|
||||
}, $timeout);
|
||||
}
|
||||
|
||||
sub is_unit_active($;$) {
|
||||
my ($unit) = @_;
|
||||
|
||||
my $bus = Net::DBus->system();
|
||||
my $reactor = Net::DBus::Reactor->main();
|
||||
|
||||
my $service = $bus->get_service('org.freedesktop.systemd1');
|
||||
my $if = $service->get_object('/org/freedesktop/systemd1', 'org.freedesktop.systemd1.Manager');
|
||||
|
||||
my $unit_path = eval { $if->GetUnit($unit) }
|
||||
or return 0;
|
||||
$if = $service->get_object($unit_path, 'org.freedesktop.systemd1.Unit')
|
||||
or return 0;
|
||||
my $state = $if->ActiveState;
|
||||
return defined($state) && $state eq 'active';
|
||||
}
|
||||
|
||||
sub read_ini {
|
||||
my ($filename) = @_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user