| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Service::FreeBSD; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
24
|
use v5.12.5; |
|
|
1
|
|
|
|
|
8
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
14
|
|
|
|
1
|
|
|
|
|
40
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
11
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
80
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use Rex::Commands::Fs; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
8
|
|
|
14
|
1
|
|
|
1
|
|
7
|
use Rex::Commands::File; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
7
|
|
|
15
|
1
|
|
|
1
|
|
9
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
6
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
31
|
use base qw(Rex::Service::Base); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
719
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
0
|
|
|
0
|
0
|
|
my $that = shift; |
|
21
|
0
|
|
0
|
|
|
|
my $proto = ref($that) || $that; |
|
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
|
|
|
|
|
|
|
sub ensure { |
|
39
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
} or do { |
|
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
|
0
|
|
|
|
|
unless ($rcvar) { |
|
55
|
0
|
|
|
|
|
|
Rex::Logger::info( "Error getting service name.", "error" ); |
|
56
|
0
|
|
|
|
|
|
return 0; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
0
|
0
|
|
|
|
if ( $what =~ /^stop/ ) { |
|
|
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->stop( $service, $options ); |
|
61
|
0
|
|
|
|
|
|
my $stop_regexp = qr/^\s*${rcvar}=((?i)["']?YES["']?)/; |
|
62
|
0
|
0
|
|
|
|
|
if ( $rcvalue =~ m/^YES$/i ) { |
|
63
|
0
|
|
|
|
|
|
file "/etc/rc.conf.d/${service}", ensure => "absent"; |
|
64
|
0
|
|
|
|
|
|
file "/usr/local/etc/rc.conf.d/${service}", ensure => "absent"; |
|
65
|
0
|
0
|
|
|
|
|
if ( is_file("/etc/rc.conf.local") ) { |
|
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/ ) { |
|
72
|
0
|
|
|
|
|
|
$self->start( $service, $options ); |
|
73
|
0
|
|
|
|
|
|
my $start_regexp = qr/^\s*${rcvar}=/; |
|
74
|
0
|
0
|
|
|
|
|
unless ( $rcvalue =~ m/^YES$/i ) { |
|
75
|
0
|
|
|
|
|
|
file "/etc/rc.conf.d/${service}", ensure => "absent"; |
|
76
|
0
|
|
|
|
|
|
file "/usr/local/etc/rc.conf.d/${service}", ensure => "absent"; |
|
77
|
0
|
0
|
|
|
|
|
if ( is_file("/etc/rc.conf.local") ) { |
|
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; |