This file is indexed.

/usr/share/perl5/Rex/Service.pm is in rex 1.4.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:

package Rex::Service;

use strict;
use warnings;

our $VERSION = '1.4.1'; # VERSION

use Rex::Config;
use Rex::Commands::Run;
use Rex::Commands::Gather;
use Rex::Hardware;
use Rex::Hardware::Host;
use Rex::Helper::Run;
use Rex::Logger;

my %SERVICE_PROVIDER;

sub register_service_provider {
  my ( $class, $service_name, $service_class ) = @_;
  $SERVICE_PROVIDER{"\L$service_name"} = $service_class;
  return 1;
}

sub get {

  my $operatingsystem = Rex::Hardware::Host->get_operating_system();

  i_run "systemctl --no-pager > /dev/null";
  my $can_run_systemctl = $? == 0 ? 1 : 0;

  my $class;

  $class = "Rex::Service::" . $operatingsystem;
  if ( is_redhat($operatingsystem) && $can_run_systemctl ) {
    $class = "Rex::Service::Redhat::systemd";
  }
  elsif ( is_redhat($operatingsystem) ) {

    # this also counts for fedora, centos, ...
    $class = "Rex::Service::Redhat";
  }
  elsif ( is_suse($operatingsystem) && $can_run_systemctl ) {
    $class = "Rex::Service::SuSE::systemd";
  }
  elsif ( is_alt($operatingsystem) && $can_run_systemctl ) {
    $class = "Rex::Service::ALT::systemd";
  }
  elsif ( is_gentoo($operatingsystem) && $can_run_systemctl ) {
    $class = "Rex::Service::Gentoo::systemd";
  }
  elsif ( is_mageia($operatingsystem) && $can_run_systemctl ) {
    $class = "Rex::Service::Mageia::systemd";
  }
  elsif ( is_debian($operatingsystem) && $can_run_systemctl ) {

    # this also counts for Ubuntu and LinuxMint
    $class = "Rex::Service::Debian::systemd";
  }
  elsif ( is_debian($operatingsystem) ) {
    $class = "Rex::Service::Debian";
  }
  elsif ( is_arch($operatingsystem) && $can_run_systemctl ) {
    $class = "Rex::Service::Arch::systemd";
  }

  my $provider_for = Rex::Config->get("service_provider") || {};
  my $provider;

  if ( ref($provider_for) && exists $provider_for->{$operatingsystem} ) {
    $provider = $provider_for->{$operatingsystem};
    $class .= "::\L$provider";
  }
  elsif ( exists $SERVICE_PROVIDER{$provider_for} ) {
    $class = $SERVICE_PROVIDER{$provider_for};
  }

  Rex::Logger::debug("service using class: $class");
  eval "use $class";

  if ($@) {

    Rex::Logger::info("OS ($operatingsystem) not supported");
    exit 1;

  }

  return $class->new;

}

1;