class LinuxAdmin::SystemdService
Public Instance Methods
disable()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 14 def disable Common.run!(command_path, :params => ["disable", name]) self end
enable()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 9 def enable Common.run!(command_path, :params => ["enable", name]) self end
reload()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 45 def reload Common.run!(command_path, :params => ["reload", name]) self end
restart()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 33 def restart status = Common.run(command_path, :params => ["restart", name]).exit_status # attempt to manually stop/start if restart fails if status != 0 stop start end self end
running?()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 5 def running? Common.run(command_path, :params => ["status", name]).success? end
show()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 54 def show output = Common.run!(command_path, :params => ["show", name]).output output.split("\n").each_with_object({}) do |line, h| k, v = line.split("=", 2) h[k] = cast_show_value(k, v) end end
start(enable = false)
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 19 def start(enable = false) if enable Common.run!(command_path, :params => ["enable", "--now", name]) else Common.run!(command_path, :params => ["start", name]) end self end
status()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 50 def status Common.run(command_path, :params => ["status", name]).output end
stop()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 28 def stop Common.run!(command_path, :params => ["stop", name]) self end
Private Instance Methods
cast_show_value(key, value)
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 68 def cast_show_value(key, value) return value.to_i if value =~ /^\d+$/ case key when /^.*Timestamp$/ Time.parse(value) when /Exec(Start|Stop)/ parse_exec_value(value) else value end end
command_path()
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 64 def command_path Common.cmd(:systemctl) end
parse_exec_value(value)
click to toggle source
# File lib/linux_admin/service/systemd_service.rb, line 81 def parse_exec_value(value) value[1..-2].strip.split(" ; ").map { |s| s.split("=", 2) }.to_h end