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 =
The combination "--full --no-legend --no-pager --plain" is appropriate for automated processing of systemctl output. https://github.com/systemd/systemd/commit/1cabd2d0c56b7de73e4a4fb645f3bbed4a528d2c
" --plain --full --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
- .execute(command) ⇒ #command, ...
-
.service_units ⇒ Array<String>
Like ["a.service", "b.service"].
-
.socket_units ⇒ Array<String>
Like ["a.socket", "b.socket"].
-
.target_units ⇒ Array<String>
Like ["a.target", "b.target"].
Class Method Details
.execute(command) ⇒ #command, ...
40 41 42 43 44 45 46 47 48 |
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 40 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_units ⇒ Array<String>
Returns like ["a.service", "b.service"].
64 65 66 67 68 69 70 71 72 73 74 |
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 64 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_units ⇒ Array<String>
Returns like ["a.socket", "b.socket"].
51 52 53 54 55 56 57 58 59 60 61 |
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 51 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_units ⇒ Array<String>
Returns like ["a.target", "b.target"].
77 78 79 80 81 82 83 84 85 86 87 |
# File 'library/systemd/src/lib/yast2/systemctl.rb', line 77 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 |