File Coverage

lib/Rex/Service/Ubuntu.pm
Criterion Covered Total %
statement 8 22 36.3
branch 0 4 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod 0 2 0.0
total 11 36 30.5


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Service::Ubuntu;
6              
7 1     1   16 use v5.12.5;
  1         14  
8 1     1   5 use warnings;
  1         3  
  1         60  
9              
10             our $VERSION = '1.14.3'; # VERSION
11              
12 1     1   12 use base qw(Rex::Service::Base);
  1         4  
  1         404  
13              
14             sub new {
15 0     0 0   my $that = shift;
16 0   0       my $proto = ref($that) || $that;
17 0           my $self = $proto->SUPER::new(@_);
18              
19 0           bless( $self, $proto );
20              
21             $self->{commands} = {
22 0           start => '/usr/sbin/service %s start',
23             restart => '/usr/sbin/service %s restart',
24             stop => '/usr/sbin/service %s stop',
25             reload => '/usr/sbin/service %s reload',
26             status => '/usr/sbin/service %s status',
27             ensure_stop => '/usr/sbin/update-rc.d -f %s remove',
28             ensure_start => '/usr/sbin/update-rc.d %s defaults',
29             action => '/usr/sbin/service %s %s',
30             service_exists => '/usr/sbin/service --status-all 2>&1 | grep %s',
31             };
32              
33 0           return $self;
34             }
35              
36             sub status {
37 0     0 0   my ( $self, $service, $options ) = @_;
38              
39 0           my $ret = $self->SUPER::status( $service, $options );
40              
41             # bad... really bad ...
42 0 0         if ( $ret == 0 ) {
43 0           return 0;
44             }
45              
46 0           my $output = $self->get_output;
47              
48 0 0         if ( $output =~ m/NOT running|stop\//ms ) {
49 0           return 0;
50             }
51              
52 0           return 1;
53             }
54              
55             1;