line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
16
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
131
|
|
2
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
183
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Solaris::SMF::Service; |
5
|
|
|
|
|
|
|
$Solaris::SMF::Service::VERSION = '1.0.0'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Encapsulate Solaris 10 services in Perl |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
4
|
|
|
4
|
|
7
|
eval { require Data::Dumper; }; |
|
4
|
|
|
|
|
77
|
|
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
14
|
use Params::Validate qw( validate validate_pos :types ); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
527
|
|
13
|
4
|
|
|
4
|
|
20
|
use Carp; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
4696
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $debug = $ENV{RELEASE_TESTING} ? $ENV{RELEASE_TESTING} : 0; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _svcs { |
19
|
0
|
|
|
0
|
|
|
my $self = shift; |
20
|
0
|
|
|
|
|
|
local $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin'; |
21
|
0
|
0
|
|
|
|
|
open my $svc_list, '-|', " svcs -aH '$self->{FMRI}' 2>/dev/null" |
22
|
|
|
|
|
|
|
or croak 'Unable to query SMF services'; |
23
|
0
|
|
|
|
|
|
while ( my $svc_line = <$svc_list> ) { |
24
|
0
|
|
|
|
|
|
my ( $state, $date, $FMRI ) = ( |
25
|
|
|
|
|
|
|
$svc_line =~ m/ |
26
|
|
|
|
|
|
|
^ |
27
|
|
|
|
|
|
|
([^\s]+) # Current state |
28
|
|
|
|
|
|
|
[\s]+ |
29
|
|
|
|
|
|
|
([^\s]+) # Date this state was set |
30
|
|
|
|
|
|
|
[\s]+ |
31
|
|
|
|
|
|
|
( (?: svc: | lrc: ) [^\s]+ ) # FMRI |
32
|
|
|
|
|
|
|
\n? |
33
|
|
|
|
|
|
|
$ |
34
|
|
|
|
|
|
|
/xms |
35
|
|
|
|
|
|
|
); |
36
|
0
|
0
|
|
|
|
|
if ($FMRI) { |
37
|
0
|
|
|
|
|
|
close $svc_list; |
38
|
0
|
|
|
|
|
|
return ( $state, $date ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
croak "Unable to determine status of $self->{FMRI}"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _svcprop { |
45
|
0
|
0
|
|
0
|
|
|
$debug && warn( '_svcprop ' . join( ',', @_ ) ); |
46
|
0
|
|
|
|
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
local $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin'; |
48
|
0
|
0
|
|
|
|
|
open my $svcprop_list, '-|', " svcprop '$self->{FMRI}' 2>/dev/null" |
49
|
|
|
|
|
|
|
or croak 'Unable to query SMF service properties'; |
50
|
0
|
|
|
|
|
|
my %properties; |
51
|
0
|
|
|
|
|
|
while ( my $svcprop_line = <$svcprop_list> ) { |
52
|
0
|
|
|
|
|
|
my ( $name, $type, $value ) = ( |
53
|
|
|
|
|
|
|
$svcprop_line =~ m/ |
54
|
|
|
|
|
|
|
^ |
55
|
|
|
|
|
|
|
([^\s]+) # Property name |
56
|
|
|
|
|
|
|
[\s]+ |
57
|
|
|
|
|
|
|
([^\s]+) # Type of property |
58
|
|
|
|
|
|
|
[\s]+ |
59
|
|
|
|
|
|
|
([^\s]*[^\n]*) # Value of property |
60
|
|
|
|
|
|
|
$ |
61
|
|
|
|
|
|
|
/xms |
62
|
|
|
|
|
|
|
); |
63
|
0
|
0
|
|
|
|
|
if ($name) { |
64
|
0
|
|
|
|
|
|
$properties{$name}{type} = $type; |
65
|
0
|
|
|
|
|
|
$properties{$name}{value} = $value; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
0
|
|
|
|
|
$debug && print STDERR Data::Dumper->Dump( [ $name, $type, $value ], |
68
|
|
|
|
|
|
|
[qw($name $type $value)] ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
$debug |
71
|
0
|
0
|
|
|
|
|
&& print STDERR Data::Dumper->Dump( [ \%properties ], |
72
|
|
|
|
|
|
|
[qw(%properties)] ); |
73
|
0
|
|
|
|
|
|
return \%properties; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _svcadm { |
77
|
0
|
0
|
|
0
|
|
|
$debug && warn( '_svcadm ' . join( ',', @_ ) ); |
78
|
0
|
|
|
|
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
my $svcadm_action = shift; |
80
|
0
|
|
|
|
|
|
local $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin'; |
81
|
0
|
0
|
|
|
|
|
open my $svc_adm, '-|', " svcadm $svcadm_action '$self->{FMRI}' 2>&1" |
82
|
|
|
|
|
|
|
or croak 'Unable to administer SMF services'; |
83
|
0
|
|
|
|
|
|
close $svc_adm; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub new { |
88
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'new ' . join( ',', @_ ) ); |
89
|
0
|
|
|
|
|
|
my $class = shift; |
90
|
0
|
|
|
|
|
|
my $FMRI = shift; |
91
|
0
|
|
|
|
|
|
my $service = bless {}, __PACKAGE__; |
92
|
0
|
|
|
|
|
|
$service->{FMRI} = $FMRI; |
93
|
0
|
|
|
|
|
|
return $service; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub status { |
98
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'status ' . join( ',', @_ ) ); |
99
|
0
|
|
|
|
|
|
my $self = shift; |
100
|
0
|
|
|
|
|
|
my ( $status, $date ) = $self->_svcs(); |
101
|
0
|
0
|
|
|
|
|
$debug |
102
|
|
|
|
|
|
|
&& warn( |
103
|
|
|
|
|
|
|
Data::Dumper->Dump( [ $status, $date ], [qw($status $date)] ) ); |
104
|
0
|
|
|
|
|
|
return $status; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub FMRI { |
109
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'FMRI ' . join( ',', @_ ) ); |
110
|
0
|
|
|
|
|
|
my $self = shift; |
111
|
0
|
|
|
|
|
|
return $self->{FMRI}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub properties { |
116
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'properties ' . join( ',', @_ ) ); |
117
|
0
|
|
|
|
|
|
my $self = shift; |
118
|
0
|
|
|
|
|
|
my $properties = $self->_svcprop(); |
119
|
0
|
|
|
|
|
|
return %{$properties}; |
|
0
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub property { |
124
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'property ' . join( ',', @_ ) ); |
125
|
0
|
|
|
|
|
|
my $self = shift; |
126
|
0
|
|
|
|
|
|
my $p = validate_pos( @_, { type => SCALAR } ); |
127
|
0
|
|
|
|
|
|
my ($property_name) = @{$p}; |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my $properties = $self->_svcprop(); |
130
|
0
|
0
|
|
|
|
|
$debug && warn( Data::Dumper->Dump( [$properties], [qw($properties)] ) ); |
131
|
0
|
0
|
|
|
|
|
if ( defined $properties->{$property_name} ) { |
132
|
0
|
|
|
|
|
|
return $properties->{$property_name}{value}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
else { |
135
|
0
|
|
|
|
|
|
carp "Unable to find property '$property_name' for " . $self->{FMRI}; |
136
|
0
|
|
|
|
|
|
undef; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub property_type { |
142
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'property_type ' . join( ',', @_ ) ); |
143
|
0
|
|
|
|
|
|
my $self = shift; |
144
|
0
|
|
|
|
|
|
my $p = validate_pos( @_, { type => SCALAR } ); |
145
|
0
|
|
|
|
|
|
my ($property_name) = @{$p}; |
|
0
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
my $properties = $self->_svcprop(); |
148
|
0
|
0
|
|
|
|
|
$debug && warn( Data::Dumper->Dump( [$properties], [qw($properties)] ) ); |
149
|
0
|
0
|
|
|
|
|
if ( defined $properties->{$property_name} ) { |
150
|
0
|
|
|
|
|
|
return $properties->{$property_name}{type}; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
else { |
153
|
0
|
|
|
|
|
|
carp "Unable to find property '$property_name' for " . $self->{FMRI}; |
154
|
0
|
|
|
|
|
|
undef; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub disable { |
160
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'disable ' . join( ',', @_ ) ); |
161
|
0
|
|
|
|
|
|
my $self = shift; |
162
|
0
|
|
|
|
|
|
return $self->_svcadm('disable'); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub stop { |
167
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'stop ' . join( ',', @_ ) ); |
168
|
0
|
|
|
|
|
|
my $self = shift; |
169
|
0
|
|
|
|
|
|
return $self->_svcadm('disable -t'); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub enable { |
174
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'enable ' . join( ',', @_ ) ); |
175
|
0
|
|
|
|
|
|
my $self = shift; |
176
|
0
|
|
|
|
|
|
return $self->_svcadm('enable'); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub start { |
181
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'start ' . join( ',', @_ ) ); |
182
|
0
|
|
|
|
|
|
my $self = shift; |
183
|
0
|
|
|
|
|
|
return $self->_svcadm('enable -t'); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub refresh { |
188
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'refresh ' . join( ',', @_ ) ); |
189
|
0
|
|
|
|
|
|
my $self = shift; |
190
|
0
|
|
|
|
|
|
return $self->_svcadm('refresh'); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub clear { |
195
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'clear ' . join( ',', @_ ) ); |
196
|
0
|
|
|
|
|
|
my $self = shift; |
197
|
0
|
|
|
|
|
|
return $self->_svcadm('clear'); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub mark { |
202
|
0
|
0
|
|
0
|
1
|
|
$debug && warn( 'mark ' . join( ',', @_ ) ); |
203
|
0
|
|
|
|
|
|
my $self = shift; |
204
|
0
|
|
|
|
|
|
return $self->_svcadm('mark'); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; # End of Solaris::SMF::Service |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
__END__ |