Class: AethernalAgent::Loader

Inherits:
Object
  • Object
show all
Includes:
Apt, Utils
Defined in:
lib/aethernal_agent/loader.rb

Instance Attribute 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 Apt

#add_apt_ppa, #apt_package, #apt_update, included

Constructor Details

#initializeLoader

Returns a new instance of Loader.



12
13
14
15
16
# File 'lib/aethernal_agent/loader.rb', line 12

def initialize
  STDOUT.sync = true
  self.loaded_manifests = []
  self.dynamic_load
end

Instance Attribute Details

#loaded_manifestsObject

Returns the value of attribute loaded_manifests.



10
11
12
# File 'lib/aethernal_agent/loader.rb', line 10

def loaded_manifests
  @loaded_manifests
end

Instance Method Details

#dynamic_loadObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aethernal_agent/loader.rb', line 24

def dynamic_load
  AethernalAgent.logger.info "Checking embedded plugins"
  embedded_plugins = File.expand_path(File.join(File.dirname(__FILE__), 'plugins/*/*.yml'))
  require_plugins_from_paths(embedded_plugins)

  AethernalAgent.logger.info "Checking custom plugins"
  custom_plugins = File.join(Dir.home,".config", "bytesized", "aethernal_agent", "plugins", "*", "*.yml")
  require_plugins_from_paths(custom_plugins)

  AethernalAgent.logger.info "Ensuring server state"
  self.ensure_server_state
end

#ensure_server_stateObject



18
19
20
21
22
# File 'lib/aethernal_agent/loader.rb', line 18

def ensure_server_state
  apt_package(packages: ["unzip", "apache2", "build-essential", "libsqlite3-dev", "sqlite3", "libapache2-mpm-itk"])

  AethernalAgent::Apache.ensure_default_config
end

#read_manifest(file_path) ⇒ Object



51
52
53
54
# File 'lib/aethernal_agent/loader.rb', line 51

def read_manifest(file_path)
  AethernalAgent.logger.info "Loading manifest from '#{file_path}'"
  return OpenStruct.new(YAML.load_file(file_path))
end

#require_plugins_from_paths(paths) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/aethernal_agent/loader.rb', line 37

def require_plugins_from_paths(paths)
  AethernalAgent.logger.debug "Checking in #{paths}"
  Dir[paths].each do |file_path|
    m = read_manifest(file_path)
    AethernalAgent.logger.info "Loading #{m.name} - v#{m.version} from #{m.script_name}"
    if check_manifest(m)
      require file_path.gsub("manifest.yml",m["script_name"])
      self.loaded_manifests << m
    else
      AethernalAgent.logger.warn "Manifest #{m.name} required aethernal_agent version '#{m.required_aethernal_agent_version}' but '#{AethernalAgent::VERSION}' is loaded, not loading plugin."
    end
  end
end