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



39
40
41
42
# File 'lib/linux_admin/service/systemd_service.rb', line 39

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

#restartObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/linux_admin/service/systemd_service.rb', line 27

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



48
49
50
51
52
53
54
# File 'lib/linux_admin/service/systemd_service.rb', line 48

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

#startObject



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

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

#statusObject



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

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

#stopObject



22
23
24
25
# File 'lib/linux_admin/service/systemd_service.rb', line 22

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