Class: DanarchyDeploy::Services::Init::Systemd

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/services/init/systemd.rb

Instance Method Summary collapse

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, options)
  @service = service
  @options = options
end

Instance Method Details

#disableObject



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

#enableObject



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

#reloadObject



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

#restartObject



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

#startObject



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

#statusObject



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

#stopObject



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