File Coverage

blib/lib/Solaris/SMF.pm
Criterion Covered Total %
statement 25 30 83.3
branch 2 10 20.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 35 48 72.9


line stmt bran cond sub pod time code
1             package Solaris::SMF;
2              
3             BEGIN {
4 3     3   69588 eval {
5 3         3439 require Data::Dumper;
6             }
7             };
8 3     3   33437 use warnings;
  3         8  
  3         116  
9 3     3   18 use strict;
  3         6  
  3         233  
10             require Exporter;
11             our @ISA = qw(Exporter);
12             our @EXPORT = qw( get_services );
13 3     3   2964 use Params::Validate qw ( validate :types );
  3         35308  
  3         794  
14 3     3   1873 use Solaris::SMF::Service;
  3         9  
  3         92  
15 3     3   22 use Carp;
  3         5  
  3         1162  
16              
17             my $debug = $ENV{RELEASE_TESTING} ? $ENV{RELEASE_TESTING} : 0;
18              
19             =head1 NAME
20              
21             Solaris::SMF - Manipulate Solaris 10 services from Perl
22              
23             =head1 VERSION
24              
25             Version 0.04
26              
27             =cut
28              
29             our $VERSION = '0.04';
30              
31             =head1 SYNOPSIS
32              
33             Interface to Sun's Service Management Facility in Solaris 10. This module provides
34             a wrapper around 'svcs', 'svcadm' and 'svccfg'.
35              
36             The SMF in Solaris is a replacement for inetd as well as the runlevel-based stopping
37             and starting of daemons. Service definitions are stored in an XML database.
38              
39             The biggest advantages in using SMF are the resiliency support, consistent interface and
40             inter-service dependencies it offers. Services that die for any reason can be automatically
41             restarted by the operating system; all services can be enabled or disabled using the same
42             commands; and services can be started as soon as all the services they depend upon have
43             been started, rather than at a fixed point in the boot process.
44              
45              
46             =head1 EXPORT
47              
48              
49              
50             =head1 FUNCTIONS
51              
52             =head2 get_services
53              
54             Get a list of SMF services, using an optional wildcard as a filter. The default is to return all services.
55              
56             Returns a list of Solaris::SMF::Service objects.
57              
58             =cut
59              
60             sub get_services {
61 4 50   4 1 3862 $debug && warn( 'get_services ' . join( ',', @_ ) );
62 4         290 my %p = validate( @_, { wildcard => { type => SCALAR, default => '*' } } );
63 4         393 local $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin';
64 4         8 my @service_list;
65 4 50       29594 open my $svc_list, '-|', " svcs -aH '$p{wildcard}' 2>/dev/null"
66             or die 'Unable to query SMF services';
67 4         6609 while ( my $svc_line = <$svc_list> ) {
68 0 0       0 $debug
69             && warn($svc_line);
70 0         0 my ( $state, $date, $FMRI ) = (
71             $svc_line =~ m/
72             ^
73             ([^\s]+) # Current state
74             [\s]+
75             ([^\s]+) # Date this state was set
76             [\s]+
77             ( (?:svc:|lrc:) [^\s]+) # FMRI
78             \n?
79             $
80             /xms
81             );
82 0 0       0 $debug &&
83             warn(
84             Data::Dumper->Dump(
85             [ $state, $date, $FMRI ],
86             [qw($state $date $FMRI)]
87             )
88             );
89 0 0       0 if ($FMRI) {
90 0         0 push( @service_list, Solaris::SMF::Service->new($FMRI) );
91             }
92             }
93 4         960 close $svc_list;
94 4         1401 return @service_list;
95             }
96              
97             =head1 AUTHOR
98              
99             Brad Macpherson, C<< >>
100              
101             =head1 BUGS
102              
103             Please report any bugs or feature requests to C, or through
104             the web interface at L. I will be notified, and then you'll
105             automatically be notified of progress on your bug as I make changes.
106              
107              
108              
109              
110             =head1 SUPPORT
111              
112             You can find documentation for this module with the perldoc command.
113              
114             perldoc Solaris::SMF
115              
116              
117             You can also look for information at:
118              
119             =over 4
120              
121             =item * RT: CPAN's request tracker
122              
123             L
124              
125             =item * AnnoCPAN: Annotated CPAN documentation
126              
127             L
128              
129             =item * CPAN Ratings
130              
131             L
132              
133             =item * Search CPAN
134              
135             L
136              
137             =back
138              
139              
140             =head1 ACKNOWLEDGEMENTS
141              
142              
143             =head1 COPYRIGHT & LICENCE
144              
145             Copyright 2009 Brad Macpherson.
146              
147             This program is free software; you can redistribute it and/or modify it
148             under the terms of either: the GNU General Public Licence as published
149             by the Free Software Foundation; or the Artistic Licence.
150              
151             See http://dev.perl.org/licenses/ for more information.
152              
153              
154             =cut
155              
156             1; # End of Solaris::SMF