Class: Avm::Stereotypes::EacUbuntuBase0::Apache::Site

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

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 16

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

#available_pathObject



12
13
14
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 12

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

#disableObject



20
21
22
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 20

def disable
  apache.host_env.command('sudo', 'a2dissite', name).execute!
end

#enableObject



24
25
26
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 24

def enable
  apache.host_env.command('sudo', 'a2ensite', name).execute!
end

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 32

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

#enabled_pathObject



28
29
30
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 28

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

#removeObject



36
37
38
39
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 36

def remove
  remove_disabled
  remove_available
end

#remove_availableObject



41
42
43
44
45
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 41

def remove_available
  raise 'Remove enabled before' if enabled?

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

#remove_disabledObject



47
48
49
50
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 47

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

#write(content) ⇒ Object



52
53
54
55
56
# File 'lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb', line 52

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