| 1 | # | ||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Rex::Service::Redhat::systemd; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | ▶ | use Rex::Helper::Run; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | ▶ | use base qw(Rex::Service::Base); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 17 | 0 | my $that = shift; | |||||||||||||||||||
| 18 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 19 | 0 | my $self = $proto->SUPER::new(@_); | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | bless( $self, $proto ); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | $self->{commands} = { | ||||||||||||||||||||
| 24 | 0 | start => 'systemctl --no-pager start %s', | |||||||||||||||||||
| 25 | restart => 'systemctl --no-pager restart %s', | ||||||||||||||||||||
| 26 | stop => 'systemctl --no-pager stop %s', | ||||||||||||||||||||
| 27 | reload => 'systemctl --no-pager reload %s', | ||||||||||||||||||||
| 28 | status => 'systemctl --no-pager is-active %s', | ||||||||||||||||||||
| 29 | ensure_stop => 'systemctl --no-pager disable %s', | ||||||||||||||||||||
| 30 | ensure_start => 'systemctl --no-pager enable %s', | ||||||||||||||||||||
| 31 | service_exists => 'systemctl --no-pager show %s | grep LoadState=loaded', | ||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | return $self; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # all systemd services must end with .service | ||||||||||||||||||||
| 38 | # so it will be appended if there is no "." in the name. | ||||||||||||||||||||
| 39 | 0 | ▶ | sub _prepare_service_name { | ||||||||||||||||||
|
Subroutine
_prepare_service_name: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 40 | 0 | my ( $self, $service ) = @_; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | unless ( $service =~ m/\./ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | $service .= ".service"; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | $self->SUPER::_prepare_service_name($service); | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | return $service; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | sub action { | ||||||||||||||||||
|
Subroutine
action: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 52 | 0 | my ( $self, $service, $action ) = @_; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | my $ret_val; | |||||||||||||||||||
| 55 | eval { | ||||||||||||||||||||
| 56 | 0 | i_run "systemctl --no-pager $action $service >/dev/null", nohup => 1; | |||||||||||||||||||
| 57 | 0 | $ret_val = 1; | |||||||||||||||||||
| 58 | 0 | 1; | |||||||||||||||||||
| 59 | 0 | ▶ | } or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | $ret_val = 0; | |||||||||||||||||||
| 61 | }; | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | return $ret_val; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 1 | 1; | |||||||||||||||||||