Class: AethernalAgent::Apache

Inherits:
Object
  • Object
show all
Extended by:
Utils
Includes:
Errors, Filesystem, Utils
Defined in:
lib/aethernal_agent/apache/apache.rb

Instance Attribute Summary collapse

Attributes included from Errors

#global_errors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

apt_running?, check_manifest, container_domain, current_xdg_runtime_dir, docker_container_name, get_current_uid, get_global_config, global_config_path, port_is_free, prepare_test_config, print_system, random_port, random_string, run_as, run_command, run_systemd_plain, set_global_config, systemd_text_for_service, ubuntu_release, wait_on_apt, wait_on_file, wait_on_port

Methods included from Errors

#add_errors, #get_errors

Methods included from Filesystem

#aethernal_agent_file, #aethernal_agent_folder, #copy, #directory, #file, #file_settings, #files_folder, #files_path, #home_folder_path, #meta_folder, #meta_path, #set_ownership, #set_permissions, #template_path, #templates_folder, #write_template

Constructor Details

#initialize(options = {}) ⇒ Apache

Returns a new instance of Apache.



20
21
22
# File 'lib/aethernal_agent/apache/apache.rb', line 20

def initialize(options = {})
  self.user = options['user'] || 'root'
end

Instance Attribute Details

#userObject

Returns the value of attribute user.



11
12
13
# File 'lib/aethernal_agent/apache/apache.rb', line 11

def user
  @user
end

Class Method Details

.ensure_default_configObject



13
14
15
16
17
18
# File 'lib/aethernal_agent/apache/apache.rb', line 13

def self.ensure_default_config
  run_command("a2enmod rewrite proxy scgi headers proxy proxy_html proxy_http ssl xml2enc proxy_wstunnel mpm_itk")
  run_command("echo 'ProxyPass /aethernal http://127.0.0.1:4567/' > /etc/apache2/sites-available/aa-default.conf")
  run_command("a2ensite aa-default")
  run_command("systemctl restart apache2")
end

Instance Method Details

#apache_user_conf_path(app_name = nil) ⇒ Object



67
68
69
70
71
# File 'lib/aethernal_agent/apache/apache.rb', line 67

def apache_user_conf_path(app_name = nil)
  path = File.join("/etc/apache2/users", self.user)
  path = File.join(path, "#{app_name}.conf") if app_name
  path
end

#ensure_base_config(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/aethernal_agent/apache/apache.rb', line 35

def ensure_base_config(options = {})
  config_file = File.join(File.expand_path(File.dirname(__FILE__)), "templates","aa-user.conf.erb")

  container_name = get_global_config(:container_name)
  host_name = get_global_config(:hostname)

  add_errors("hostname not found in global config") unless host_name
  add_errors("container_name not found in global config") unless container_name

  write_template(config_file, "/etc/apache2/sites-available/aethernal_agent-#{self.user}.conf",{
    home_folder: home_folder_path,
    user: self.user,
    container_name: container_name,
    host_name: host_name,
    custom_domains: options[:custom_domains]
  })

  directory(home_folder_path("www"), owner: self.user)

  run_command("a2ensite aethernal_agent-#{self.user}")

  return nil
end

#reloadObject



59
60
61
# File 'lib/aethernal_agent/apache/apache.rb', line 59

def reload
  run_command("systemctl reload apache2")
end

#remove_app_config(app_name) ⇒ Object



31
32
33
# File 'lib/aethernal_agent/apache/apache.rb', line 31

def remove_app_config(app_name)
  file(apache_user_conf_path(app_name), action: :delete)
end

#restartObject



63
64
65
# File 'lib/aethernal_agent/apache/apache.rb', line 63

def restart
  run_command("systemctl restart apache2")
end

#write_app_config(template_path, app_name, port) ⇒ Object



24
25
26
27
28
29
# File 'lib/aethernal_agent/apache/apache.rb', line 24

def write_app_config(template_path, app_name, port)
  directory(apache_user_conf_path)
  write_template(template_path, apache_user_conf_path(app_name), {port: port})

  reload
end