line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
54258
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
108
|
|
2
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
205
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Solaris::SMF; |
5
|
|
|
|
|
|
|
$Solaris::SMF::VERSION = '1.0.1'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Manipulate Solaris 10 services from Perl |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT = qw( get_services ); |
11
|
3
|
|
|
3
|
|
1614
|
use Params::Validate qw ( validate :types ); |
|
3
|
|
|
|
|
24640
|
|
|
3
|
|
|
|
|
604
|
|
12
|
3
|
|
|
3
|
|
1229
|
use Solaris::SMF::Service; |
|
3
|
|
|
|
|
34
|
|
|
3
|
|
|
|
|
89
|
|
13
|
3
|
|
|
3
|
|
18
|
use Log::Any qw($log); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
10
|
|
14
|
3
|
|
|
3
|
|
139
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
801
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub get_services { |
18
|
0
|
0
|
|
0
|
1
|
|
$log->is_trace && $log->trace( 'get_services ' . join( ',', @_ ) ); |
19
|
0
|
|
|
|
|
|
my %p = |
20
|
|
|
|
|
|
|
validate( @_, { wildcard => { type => SCALAR, default => '*' } } ); |
21
|
0
|
|
|
|
|
|
local $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin'; |
22
|
0
|
|
|
|
|
|
my @service_list; |
23
|
0
|
0
|
|
|
|
|
open my $svc_list, '-|', " svcs -aH '$p{wildcard}' 2>/dev/null" |
24
|
|
|
|
|
|
|
or die 'Unable to query SMF services'; |
25
|
0
|
|
|
|
|
|
while ( my $svc_line = <$svc_list> ) { |
26
|
0
|
0
|
|
|
|
|
$log->is_trace && $log->trace($svc_line); |
27
|
0
|
|
|
|
|
|
my ( $state, $date, $FMRI ) = ( |
28
|
|
|
|
|
|
|
$svc_line =~ m/ |
29
|
|
|
|
|
|
|
^ |
30
|
|
|
|
|
|
|
([^\s]+) # Current state |
31
|
|
|
|
|
|
|
[\s]+ |
32
|
|
|
|
|
|
|
([^\s]+) # Date this state was set |
33
|
|
|
|
|
|
|
[\s]+ |
34
|
|
|
|
|
|
|
( (?:svc:|lrc:) [^\s]+) # FMRI |
35
|
|
|
|
|
|
|
\n? |
36
|
|
|
|
|
|
|
$ |
37
|
|
|
|
|
|
|
/xms |
38
|
|
|
|
|
|
|
); |
39
|
0
|
0
|
|
|
|
|
$log->is_trace && $log->tracef( '$state: %s $date: %s $FMRI: %s', |
40
|
|
|
|
|
|
|
$state, $date, $FMRI ); |
41
|
0
|
0
|
|
|
|
|
if ($FMRI) { |
42
|
0
|
|
|
|
|
|
push( @service_list, Solaris::SMF::Service->new($FMRI) ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
close $svc_list; |
46
|
0
|
|
|
|
|
|
return @service_list; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |