Module: Yast::Systemctl

Includes:
Logger
Defined in:
library/systemd/src/lib/yast2/systemctl.rb

Overview

Wrapper around `systemctl` command.

  • uses non-interactive flags

  • has a timeout

Constant Summary

CONTROL =
"systemctl".freeze
COMMAND_OPTIONS =
" --no-legend --no-pager --no-ask-password ".freeze
ENV_VARS =
" LANG=C TERM=dumb COLUMNS=1024 ".freeze
SYSTEMCTL =
ENV_VARS + CONTROL + COMMAND_OPTIONS
TIMEOUT =

seconds

30
BASH_SCR_PATH =
Yast::Path.new(".target.bash_output")

Class Method Summary collapse

Class Method Details

.execute(command) ⇒ #command, ...

Parameters:

Returns:

  • (#command, #stdout, #stderr, #exit)

Raises:



31
32
33
34
35
36
37
38
39
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 31

def execute(command)
  log.info("systemctl #{command}")
  command = SYSTEMCTL + command
  log.debug "Executing `systemctl` command: #{command}"
  result = ::Timeout.timeout(TIMEOUT) { SCR.Execute(BASH_SCR_PATH, command) }
  OpenStruct.new(result.merge!(command: command))
rescue ::Timeout::Error
  raise SystemctlError, "Timeout #{TIMEOUT} seconds: #{command}"
end

.service_unitsArray<String>

Returns like [“a.service”, “b.service”]

Returns:

  • (Array<String>)

    like [“a.service”, “b.service”]



55
56
57
58
59
60
61
62
63
64
65
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 55

def service_units
  services_from_files = list_unit_files(type: :service).lines.map do |line|
    first_column(line)
  end

  services_from_units = list_units(type: :service).lines.map do |line|
    first_column(line)
  end

  (services_from_files | services_from_units).compact
end

.socket_unitsArray<String>

Returns like [“a.socket”, “b.socket”]

Returns:

  • (Array<String>)

    like [“a.socket”, “b.socket”]



42
43
44
45
46
47
48
49
50
51
52
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 42

def socket_units
  sockets_from_files = list_unit_files(type: :socket).lines.map do |line|
    first_column(line)
  end

  sockets_from_units = list_units(type: :socket).lines.map do |line|
    first_column(line)
  end

  (sockets_from_files | sockets_from_units).compact
end

.target_unitsArray<String>

Returns like [“a.target”, “b.target”]

Returns:

  • (Array<String>)

    like [“a.target”, “b.target”]



68
69
70
71
72
73
74
75
76
77
78
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 68

def target_units
  targets_from_files = list_unit_files(type: :target).lines.map do |line|
    first_column(line)
  end

  targets_from_units = list_units(type: :target).lines.map do |line|
    first_column(line)
  end

  (targets_from_files | targets_from_units).compact
end