lib/Rex/Service/FreeBSD.pm

filter: Statementstmt 37.2% 22 / 59 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 2 totaltotal 30.2% 29 / 96 CC 11 SCAR 40.8
CC
11
Cov
27%
ensure
110.0
new
6.0
BEGIN
1.0
CRAP 58.9
« lib/Rex/Inventory.pm ↑ Summary lib/Rex/Commands/User.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Service::FreeBSD;
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 1 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use base qw(Rex::Service::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
20 0 my $that = shift;
21 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
22 0 my $self = $proto->SUPER::new(@_);
23  
24 0 bless( $self, $proto );
25  
26 $self->{commands} = {
27 0 start => '/usr/sbin/service %s onestart',
28 restart => '/usr/sbin/service %s onerestart',
29 stop => '/usr/sbin/service %s onestop',
30 reload => '/usr/sbin/service %s onereload',
31 status => '/usr/sbin/service %s onestatus',
32 action => '/usr/sbin/service %s %s',
33 };
34  
35 0 return $self;
36 }
37  
38 0 ▶sub ensure {
Subroutine ensure: not called CC=10 SCAR=47.0
Pod undocumented
39 0 my ( $self, $service, $options ) = @_;
40  
41 0 my $what = $options->{ensure};
42  
43 0 my $rccom = "/usr/sbin/service $service rcvar";
44 0 my $rcout;
45 eval {
46 0 $rcout = i_run $rccom;
47 0 1;
48 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $rcout = i_run($rccom); 1 } } or do { Rex::Logger::info("Running `$rccom` failed", "error"); return 0 } 0 0 0
49 0 Rex::Logger::info( "Running `$rccom` failed", "error" );
50 0 return 0;
51 };
52  
53 0 my ( $rcvar, $rcvalue ) = $rcout =~ m/^\$?(\w+)="?(\w+)"?$/m;
54 0 ▶ unless ($rcvar) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rcvar) 0 0 0
55 0 Rex::Logger::info( "Error getting service name.", "error" );
56 0 return 0;
57 }
58  
59 0 ▶ if ( $what =~ /^stop/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($what =~ /^stop/u) { } 0 0 0
elsif ($what =~ /^start/u or $what =~ /^run/u) { } 0 0 0
60 0 $self->stop( $service, $options );
61 0 my $stop_regexp = qr/^\s*${rcvar}=((?i)["']?YES["']?)/;
62 0 ▶ if ( $rcvalue =~ m/^YES$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rcvalue =~ /^YES$/iu) 0 0 0
63 0 file "/etc/rc.conf.d/${service}", ensure => "absent";
64 0 file "/usr/local/etc/rc.conf.d/${service}", ensure => "absent";
65 0 ▶ if ( is_file("/etc/rc.conf.local") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_file("/etc/rc.conf.local")) 0 0 0
66 0 delete_lines_matching "/etc/rc.conf.local", matching => $stop_regexp;
67 }
68 0 delete_lines_matching "/etc/rc.conf", matching => $stop_regexp;
69 }
70 }
71 ▶ elsif ( $what =~ /^start/ || $what =~ m/^run/ ) {
Condition0%0/3
$what =~ /^start/u or $what =~ /^run/u
l!l&&r!l&&!r
000
MC/DC0%0/2
$what =~ /^start/u or $what =~ /^run/u
$what =~ /^start/u $what =~ /^run/u
Truth table0%0/3
A or B
A= $what =~ /^start/uB= $what =~ /^run/u
ABresult
1X1
011
000
72 0 $self->start( $service, $options );
73 0 my $start_regexp = qr/^\s*${rcvar}=/;
74 0 ▶ unless ( $rcvalue =~ m/^YES$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rcvalue =~ /^YES$/iu) 0 0 0
75 0 file "/etc/rc.conf.d/${service}", ensure => "absent";
76 0 file "/usr/local/etc/rc.conf.d/${service}", ensure => "absent";
77 0 ▶ if ( is_file("/etc/rc.conf.local") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_file("/etc/rc.conf.local")) 0 0 0
78 0 delete_lines_matching "/etc/rc.conf.local", matching => $start_regexp;
79 }
80 0 append_or_amend_line "/etc/rc.conf",
81 line => "${rcvar}=\"YES\"",
82 regexp => $start_regexp;
83 }
84 }
85  
86 0 return 1;
87 }
88  
89 1 1;
« lib/Rex/Inventory.pm ↑ Summary lib/Rex/Commands/User.pm »