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)


15
16
17
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 15

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

#available_pathObject



11
12
13
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 11

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

#disableObject



19
20
21
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 19

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

#enableObject



23
24
25
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 23

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

#enabled?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 31

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

#enabled_pathObject



27
28
29
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 27

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

#removeObject



35
36
37
38
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 35

def remove
  remove_disabled
  remove_available
end

#remove_availableObject



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

def remove_available
  raise 'Remove enabled before' if enabled?

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

#remove_disabledObject



46
47
48
49
# File 'lib/avm/eac_ubuntu_base0/apache/resource.rb', line 46

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

#write(content) ⇒ Object



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

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