Class: LinuxAdmin::Service
- Inherits:
-
LinuxAdmin
- Object
- LinuxAdmin
- LinuxAdmin::Service
- Defined in:
- lib/linux_admin/service.rb
Constant Summary
Constants inherited from LinuxAdmin
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize(id) ⇒ Service
constructor
A new instance of Service.
- #restart ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Common
Constructor Details
#initialize(id) ⇒ Service
Returns a new instance of Service.
19 20 21 |
# File 'lib/linux_admin/service.rb', line 19 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/linux_admin/service.rb', line 8 def id @id end |
Instance Method Details
#disable ⇒ Object
33 34 35 36 |
# File 'lib/linux_admin/service.rb', line 33 def disable systemctl 'disable' self end |
#enable ⇒ Object
28 29 30 31 |
# File 'lib/linux_admin/service.rb', line 28 def enable systemctl 'enable' self end |
#restart ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/linux_admin/service.rb', line 50 def restart status = run(cmd(:service), :params => { nil => [id, "restart"] }).exit_status # attempt to manually stop/start if restart fails if status != 0 self.stop self.start end self end |
#running? ⇒ Boolean
23 24 25 26 |
# File 'lib/linux_admin/service.rb', line 23 def running? run(cmd(:service), :params => { nil => [id, "status"] }).exit_status == 0 end |
#start ⇒ Object
38 39 40 41 42 |
# File 'lib/linux_admin/service.rb', line 38 def start run!(cmd(:service), :params => { nil => [id, "start"] }) self end |
#stop ⇒ Object
44 45 46 47 48 |
# File 'lib/linux_admin/service.rb', line 44 def stop run!(cmd(:service), :params => { nil => [id, "stop"] }) self end |