Module: Yast2::Systemctl

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

Overview

Wrapper around systemctl command.

  • uses non-interactive flags
  • has a timeout

Defined Under Namespace

Classes: Error

Constant Summary collapse

CONTROL =
"/usr/bin/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

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

Class Method Summary collapse

Class Method Details

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

Parameters:

  • command (String)

Returns:

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

Raises:

  • (SystemctlError)

    if it times out


37
38
39
40
41
42
43
44
45
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 37

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

.service_unitsArray<String>

Returns like ["a.service", "b.service"].

Returns:

  • (Array<String>)

    like ["a.service", "b.service"]


61
62
63
64
65
66
67
68
69
70
71
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 61

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"]


48
49
50
51
52
53
54
55
56
57
58
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 48

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"]


74
75
76
77
78
79
80
81
82
83
84
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 74

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