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



14
15
16
17
18
# File 'lib/linux_admin/service/systemd_service.rb', line 14

def disable
  Common.run!(Common.cmd(:systemctl),
              :params => {nil => ["disable", name]})
  self
end

#enableObject



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

def enable
  Common.run!(Common.cmd(:systemctl),
              :params => {nil => ["enable", name]})
  self
end

#reloadObject



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

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

#restartObject



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

def restart
  status =
    Common.run(Common.cmd(:systemctl),
               :params => {nil => ["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
6
# File 'lib/linux_admin/service/systemd_service.rb', line 3

def running?
  Common.run(Common.cmd(:systemctl),
             :params => {nil => ["status", name]}).exit_status == 0
end

#startObject



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

def start
  Common.run!(Common.cmd(:systemctl),
              :params => {nil => ["start", name]})
  self
end

#statusObject



51
52
53
# File 'lib/linux_admin/service/systemd_service.rb', line 51

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

#stopObject



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

def stop
  Common.run!(Common.cmd(:systemctl),
              :params => {nil => ["stop", name]})
  self
end