class DanarchyDeploy::Services::Init::Systemd

Public Class Methods

new(service, options) click to toggle source
# File lib/danarchy_deploy/services/init/systemd.rb, line 6
def initialize(service, options)
  @service = service
  @options = options
end

Public Instance Methods

disable() click to toggle source
# File lib/danarchy_deploy/services/init/systemd.rb, line 62
def disable
  cmd = "systemctl enable #{@service}"
  DanarchyDeploy::Helpers.run_command(cmd, @options)
end
enable() click to toggle source
# File lib/danarchy_deploy/services/init/systemd.rb, line 57
def enable
  cmd = "systemctl enable #{@service}"
  DanarchyDeploy::Helpers.run_command(cmd, @options)
end
reload() click to toggle source
# 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() click to toggle source
# File lib/danarchy_deploy/services/init/systemd.rb, line 52
def restart
  cmd = "systemctl restart #{@service}"
  DanarchyDeploy::Helpers.run_command(cmd, @options)
end
start() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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