Class: DanarchyDeploy::Services::Init::Systemd
- Inherits:
-
Object
- Object
- DanarchyDeploy::Services::Init::Systemd
- Defined in:
- lib/danarchy_deploy/services/init/systemd.rb
Instance Method Summary collapse
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize(service, options) ⇒ Systemd
constructor
A new instance of Systemd.
- #reload ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(service, options) ⇒ Systemd
Returns a new instance of Systemd.
6 7 8 9 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 6 def initialize(service, ) @service = service @options = end |
Instance Method Details
#disable ⇒ Object
62 63 64 65 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 62 def disable cmd = "systemctl enable #{@service}" DanarchyDeploy::Helpers.run_command(cmd, @options) end |
#enable ⇒ Object
57 58 59 60 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 57 def enable cmd = "systemctl enable #{@service}" DanarchyDeploy::Helpers.run_command(cmd, @options) end |
#reload ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 40 def reload status = self.status cmd = if status == 'inactive' "systemctl start #{@service}" else "systemctl reload #{@service}" end DanarchyDeploy::Helpers.run_command(cmd, @options) end |
#restart ⇒ Object
52 53 54 55 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 52 def restart cmd = "systemctl restart #{@service}" DanarchyDeploy::Helpers.run_command(cmd, @options) end |
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 18 def start cmd = "systemctl start #{@service}" status = self.status if status == 'active' return status else DanarchyDeploy::Helpers.run_command(cmd, @options) end end |
#status ⇒ Object
11 12 13 14 15 16 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 11 def status cmd = "systemctl show #{@service} --no-page" # return { stdout: "Fake run: started", stderr: nil } if @options[:pretend] status = DanarchyDeploy::Helpers.run_command(cmd, @options) status[:stdout].split(/\n/).grep(/ActiveState/).first.split('=').last end |
#stop ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/danarchy_deploy/services/init/systemd.rb', line 29 def stop cmd = "systemctl #{@service} stop" status = self.status if status == 'inactive' return status else DanarchyDeploy::Helpers.run_command(cmd, @options) end end |