Class: Systemdy::Utility::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/systemdy/utility/validator.rb

Overview

Allows to add validation to a class

Class Method Summary collapse

Class Method Details

.check_if_a_service_exist(name_of_the_service) ⇒ Boolean

a method for check if a service is intalled on the system

Examples:

check if a service is intalled on the system

postgresql_service = Systemdy::Utility::Validator.check_if_a_service_exist('postgresql')
#=> true

Parameters:

  • name_of_the_service (String)

    the name of the service

Returns:

  • (Boolean)

    the presence of the service on the system



13
14
15
16
17
18
# File 'lib/systemdy/utility/validator.rb', line 13

def self.check_if_a_service_exist(name_of_the_service)
    `#{SYSTEMCTL_COMMAND} list-unit-files #{name_of_the_service}.service | wc -l`.to_i > 3
    # 'systemctl list-unit-files name_of_service.service | wc -l' command output:
    #  3  when there are not matching units(the service not exist because isn't installed on the system)
    #  >3 when there are matching units(the service exist because is installed on the system)
end