Class: LinuxAdmin::SystemdService

Inherits:
Service
  • Object
show all
Defined in:
lib/linux_admin/service/systemd_service.rb

Instance Attribute Summary

Attributes inherited from Service

#name

Instance Method Summary collapse

Methods inherited from Service

#initialize, new, service_type

Methods included from Logging

#logger

Constructor Details

This class inherits a constructor from LinuxAdmin::Service

Instance Method Details

#disableObject



12
13
14
15
# File 'lib/linux_admin/service/systemd_service.rb', line 12

def disable
  Common.run!(command_path, :params => ["disable", name])
  self
end

#enableObject



7
8
9
10
# File 'lib/linux_admin/service/systemd_service.rb', line 7

def enable
  Common.run!(command_path, :params => ["enable", name])
  self
end

#reloadObject



43
44
45
46
# File 'lib/linux_admin/service/systemd_service.rb', line 43

def reload
  Common.run!(command_path, :params => ["reload", name])
  self
end

#restartObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/linux_admin/service/systemd_service.rb', line 31

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?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/linux_admin/service/systemd_service.rb', line 3

def running?
  Common.run(command_path, :params => ["status", name]).success?
end

#showObject



52
53
54
55
56
57
58
# File 'lib/linux_admin/service/systemd_service.rb', line 52

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) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/linux_admin/service/systemd_service.rb', line 17

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

#statusObject



48
49
50
# File 'lib/linux_admin/service/systemd_service.rb', line 48

def status
  Common.run(command_path, :params => ["status", name]).output
end

#stopObject



26
27
28
29
# File 'lib/linux_admin/service/systemd_service.rb', line 26

def stop
  Common.run!(command_path, :params => ["stop", name])
  self
end