lib/Rex/Service/Redhat/systemd.pm

filter: Statementstmt 40.6% 13 / 32 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 2 totaltotal 34.0% 17 / 50 CC 4 SCAR 13.9
CC
4
Cov
33%
new
6.0
_prepare_service_name
6.0
action
6.0
CRAP 4.0
« lib/Rex/Interface/Fs/HTTP.pm ↑ Summary lib/Rex/Inventory/Hal/Object/Storage.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Service::Redhat::systemd;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use base qw(Rex::Service::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my $that = shift;
18 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
19 0 my $self = $proto->SUPER::new(@_);
20  
21 0 bless( $self, $proto );
22  
23 $self->{commands} = {
24 0 start => 'systemctl --no-pager start %s',
25 restart => 'systemctl --no-pager restart %s',
26 stop => 'systemctl --no-pager stop %s',
27 reload => 'systemctl --no-pager reload %s',
28 status => 'systemctl --no-pager is-active %s',
29 ensure_stop => 'systemctl --no-pager disable %s',
30 ensure_start => 'systemctl --no-pager enable %s',
31 service_exists => 'systemctl --no-pager show %s | grep LoadState=loaded',
32 };
33  
34 0 return $self;
35 }
36  
37 # all systemd services must end with .service
38 # so it will be appended if there is no "." in the name.
39 0 ▶sub _prepare_service_name {
Subroutine _prepare_service_name: not called CC=2 SCAR=17.9
40 0 my ( $self, $service ) = @_;
41  
42 0 ▶ unless ( $service =~ m/\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($service =~ /\./u) 0 0 0
43 0 $service .= ".service";
44 }
45  
46 0 $self->SUPER::_prepare_service_name($service);
47  
48 0 return $service;
49 }
50  
51 0 ▶sub action {
Subroutine action: not called CC=2 SCAR=17.9
Pod undocumented
52 0 my ( $self, $service, $action ) = @_;
53  
54 0 my $ret_val;
55 eval {
56 0 i_run "systemctl --no-pager $action $service >/dev/null", nohup => 1;
57 0 $ret_val = 1;
58 0 1;
59 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { i_run("systemctl --no-pager $action $service >/dev/null", "nohup", 1); $ret_val = 1; 1 } } or do { $ret_val = 0 } 0 0 0
60 0 $ret_val = 0;
61 };
62  
63 0 return $ret_val;
64 }
65  
66 1 1;
« lib/Rex/Interface/Fs/HTTP.pm ↑ Summary lib/Rex/Inventory/Hal/Object/Storage.pm »