Class: Avm::EacUbuntuBase0::Apache::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/eac_ubuntu_base0/apache/resource.rb

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 13

def available?
  apache.host_env.file(available_path).exist?
end

#available_pathObject



9
10
11
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 9

def available_path
  ::File.join(apache.etc_root, "#{directory_prefix}-available", "#{name}.conf")
end

#disableObject



17
18
19
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 17

def disable
  apache.host_env.command('sudo', "a2dis#{type}", name).execute!
end

#enableObject



21
22
23
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 21

def enable
  apache.host_env.command('sudo', "a2en#{type}", name).execute!
end

#enabled?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 29

def enabled?
  apache.host_env.file(enabled_path).exist?
end

#enabled_pathObject



25
26
27
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 25

def enabled_path
  ::File.join(apache.etc_root, "#{directory_prefix}-enabled", "#{name}.conf")
end

#removeObject



33
34
35
36
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 33

def remove
  remove_disabled
  remove_available
end

#remove_availableObject



38
39
40
41
42
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 38

def remove_available
  raise 'Remove enabled before' if enabled?

  apache.host_env.command('sudo', 'rm', '-f', available_path).execute! if available?
end

#remove_disabledObject



44
45
46
47
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 44

def remove_disabled
  disable if enabled?
  apache.host_env.command('sudo', 'rm', '-f', enabled_path).execute! if enabled?
end

#write(content) ⇒ Object



49
50
51
52
53
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 49

def write(content)
  ::EacRubyUtils::Envs.local.command('echo', content).pipe(
    apache.host_env.command('sudo', 'tee', available_path)
  ).execute!
end