Class: Luban::Deployment::Package::Installer

Inherits:
Worker show all
Defined in:
lib/luban/deployment/cli/package/installer.rb,
lib/luban/deployment/cli/package/installer/core.rb,
lib/luban/deployment/cli/package/installer/paths.rb,
lib/luban/deployment/cli/package/installer/install.rb

Defined Under Namespace

Classes: InstallFailure

Constant Summary collapse

LibExtensions =

Shared library file extension name based on OS

{ 
  Linux:  'so',   # Linux
  Darwin: 'dylib' # OSX 
}
DefaultLibExtension =

OSX

'so'
DefaultSrcFileExtName =
'tar.gz'

Constants included from Luban::Deployment::Parameters::Application

Luban::Deployment::Parameters::Application::DefaultLogrotateInterval, Luban::Deployment::Parameters::Application::DefaultLogrotateMaxAge

Constants included from Luban::Deployment::Parameters::General

Luban::Deployment::Parameters::General::DefaultLubanRootPath

Constants included from Helpers::Utils

Helpers::Utils::LogLevels

Instance Attribute Summary collapse

Attributes inherited from Worker::Base

#task

Attributes included from Helpers::Utils

#backend

Attributes included from Helpers::Configuration

#config

Instance Method Summary collapse

Methods inherited from Worker

#bin_path, #child?, #current_bin_path, #current_path, define_executable, #install_path, package_class, #package_downloads_path, #package_path, #package_tmp_path, #package_versions_path, #parent, worker_class

Methods included from Worker::Paths::Remote

#app_archives_path, #app_bin_path, #app_path, #app_tmp_path, #archived_logs_path, #archives_path, #current_app_path, #downloads_path, #env_path, #envrc_file, #luban_install_path, #package_bin_path, #package_install_path, #project_path, #releases_path, #shared_path, #tmp_path, #unset_envrc_file

Methods inherited from Worker::Base

#dry_run?, #force?, #initialize, #linux?, #method_missing, #osx?, #packages, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version

Methods included from Luban::Deployment::Parameters::Application

#env_name, #logrotate_count, #monitor_itself?, #monitorable?

Methods included from Luban::Deployment::Parameters::Base

#parameter

Methods included from Luban::Deployment::Parameters::Project

#monitor_defined?, #process_monitor_via

Methods included from Luban::Deployment::Parameters::General

included

Methods included from Helpers::Utils

#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cp, #directory?, #exists?, #file?, #hardware_name, #host, #hostname, #ln, #match?, #md5_for, #md5_for_dir, #md5_for_file, #md5_matched?, #mkdir, #mv, #now, #os_name, #os_release, #readlink, #render_template, #revision_match?, #rm, #rmdir, #sudo, #symlink?, #touch, #truncate, #upload_by_template, #url_exists?, #user_home

Methods included from Helpers::Configuration

#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?

Constructor Details

This class inherits a constructor from Luban::Deployment::Worker::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Luban::Deployment::Worker::Base

Instance Attribute Details

#build_env_varsObject (readonly)

Returns the value of attribute build_env_vars.



13
14
15
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 13

def build_env_vars
  @build_env_vars
end

#configure_optsObject (readonly)

Returns the value of attribute configure_opts.



12
13
14
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 12

def configure_opts
  @configure_opts
end

Instance Method Details

#build_pathObject



47
48
49
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 47

def build_path
  @build_path ||= package_tmp_path.join(package_full_name)
end

#cached?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 29

def cached?
  md5_matched?(src_cache_path, src_file_md5)
end

#cleanup_allObject



108
109
110
111
112
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 108

def cleanup_all
  cleanup_temp!
  cleanup_logs!
  update_result "Cleaned up temporary files in #{package_full_name} installation"
end

#configure_executableObject



17
18
19
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 17

def configure_executable
  @configure_executable ||= './configure'
end

#current_configured?Boolean Also known as: current?

Returns:

  • (Boolean)


23
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 23

def current_configured?; task.opts.current; end

#current_package_versionObject



26
27
28
29
30
31
32
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 26

def current_package_version
  if symlink?(current_path)
    File.basename(readlink(current_path))
  else
    nil
  end
end

#current_symlinked?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 19

def current_symlinked?
  current_package_version == package_version
end

#currently_used_byObject



15
16
17
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 15

def currently_used_by
  parent.currently_used_by
end

#default_configure_optsObject



34
35
36
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 34

def default_configure_opts
  @default_configure_opts ||= []
end

#downloadObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 38

def download
  info "Downloading #{package_full_name}"
  if downloaded?
    create_src_md5_file unless file?(src_md5_file_path)
    update_result "Skipped! #{package_full_name} has been downloaded ALREADY."
  else
    download_package!
    if downloaded?
      create_src_md5_file unless file?(src_md5_file_path)
      update_result "Successfully downloaded #{package_full_name}."
    else
      update_result "Failed to download #{package_full_name}. " + 
                    "Please check install log for details: #{install_log_file_path}",
                    status: :failed, level: :error
    end
  end
end

#download_urlObject



35
36
37
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 35

def download_url
  @download_url ||= File.join(source_repo, source_url_root, src_file_name)
end

#downloaded?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 25

def downloaded?
  file?(src_file_path)
end

#get_summaryObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 114

def get_summary
  status = if current_symlinked?
             current? ? " *" : "s*"
           else
             current? ? "c*" : "  "
            end

  if installed?
    installed = 'installed'
    alert = case status
            when "s*"
              "Alert! #{package_full_name} is not the current version but symlinked IMPROPERLY. " +
              "Run \"binstubs\" to fix it."
            when "c*"
              "Alert! #{package_full_name} is set as current version but NOT symlinked properly. " +
              "Run \"binstubs\" to fix it."
            end
  else
    installed = 'NOT installed'
    alert = nil
  end
  update_result summary: { name: package_full_name, installed: installed, 
                           status: status, alert: alert }
end

#include_pathObject



43
44
45
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 43

def include_path
  @include_path ||= install_path.join('include')
end

#installObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 56

def install
  info "Installing #{package_full_name}"
  if installed?
    if force?
      install!
    else
      return update_result("Skipped! #{package_full_name} has been installed ALREADY.", 
                           status: :skipped)
    end
  else
    install!
  end

  if installed?
    update_result "Successfully installed #{package_full_name}."
  else
    update_result "Failed to install #{package_full_name}. " +
                  "Please check install log for details: #{install_log_file_path}",
                  status: :failed, level: :error
  end
end

#install_log_file_nameObject



59
60
61
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 59

def install_log_file_name
  @install_log_file_name ||= "#{package_full_name}-install-#{Time.now.strftime("%Y%m%d-%H%M%S")}.log"
end

#install_log_file_pathObject



55
56
57
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 55

def install_log_file_path
  @install_log_file_path ||= install_log_path.join(install_log_file_name)
end

#install_log_pathObject



51
52
53
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 51

def install_log_path
  @install_log_path ||= package_path.join('log', package_full_name)
end

#installed?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 21

def installed?
  raise NotImplementedError, "#{self.class.name}#installed? is an abstract method."
end

#lib_pathObject



39
40
41
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 39

def lib_path
  @lib_path ||= install_path.join('lib')
end

#required_packagesObject



11
12
13
14
15
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 11

def required_packages
  @required_packages ||= 
    self.class.package_class(package_name).
      required_packages_for(package_major_version)
end

#source_repoObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 27

def source_repo
  raise NotImplementedError, "#{self.class.name}#source_repo is an abstract method."
end

#source_url_rootObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 31

def source_url_root
  raise NotImplementedError, "#{self.class.name}#source_url_root is an abstract method."
end

#src_cache_pathObject



15
16
17
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 15

def src_cache_path
  @src_cache_path ||= tmp_path.join(src_file_name)
end

#src_file_extnameObject



11
12
13
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 11

def src_file_extname
  @src_file_extname ||= DefaultSrcFileExtName
end

#src_file_md5Object



7
8
9
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 7

def src_file_md5
  @src_file_md5 ||= File.file?(src_md5_file_path) ? File.read(src_md5_file_path).chomp : ''
end

#src_file_nameObject



7
8
9
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 7

def src_file_name
  @src_file_name ||= "#{package_full_name}.#{src_file_extname}"
end

#src_file_pathObject



19
20
21
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 19

def src_file_path 
  @src_file_path ||= package_downloads_path.join(src_file_name)
end

#src_md5_file_pathObject



23
24
25
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 23

def src_md5_file_path
  @src_md5_file_path ||= package_downloads_path.join("#{src_file_name}.md5")
end

#uninstallObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 78

def uninstall
  info "Uninstalling #{package_full_name}"
  if installed?
    if current? and !force?
      update_result "Skippped! #{package_full_name} is the current version in use. " +
                    "Please switch to other version before uninstalling this version or " +
                    "use -f to force uninstalling.",
                    status: :skipped, level: :warn
    else
      uninstall!
      update_result "#{package_full_name} is uninstalled. "
    end
  else
    message = "#{package_full_name} is NOT installed."
    if directory?(install_path) or directory?(build_path)
      if force?
        uninstall!
        update_result message + 
                      "Cleaned up leftover of #{package_full_name} from last installation."
      else
        update_result message +
                      "But leftover from last installation is found. " +
                      "Use -f to force clean it up."
      end
    else
      update_result "Skipped! #{message}"
    end
  end
end

#update_binstubsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 139

def update_binstubs
  if current?
    if installed?
      update_binstubs!
      update_result "Updated #{package_name} binstubs with current version #{package_version}"
    else
      update_result "Skipped! #{package_full_name} is NOT installed yet. Please install it first.",
                    status: :failed, level: :error
    end
  else
    if current_symlinked?
      remove_binstubs!
      remove_symlinks!
      update_result "Removed #{package_name} binstubs with version #{package_version}. " +
                    "Current version of #{package_name} is NOT specified.",
                    level: :warn
    end
  end
end

#validate_download_urlObject



33
34
35
36
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 33

def validate_download_url
  info "Validating download URL for #{package_full_name}"
  validate_download_url!
end

#whence_originObject



168
169
170
171
172
173
174
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 168

def whence_origin
  get_summary
  task.result.summary[:executable] = "Not found"
  if file?(executable = bin_path.join(task.args.executable))
    task.result.summary[:executable] = executable
  end
end

#which_currentObject



159
160
161
162
163
164
165
166
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 159

def which_current
  get_summary
  task.result.summary[:executable] = "Not found"
  if current? and current_symlinked? and
     file?(executable = File.join(readlink(current_path), 'bin', task.args.executable))
    task.result.summary[:executable] = executable
  end
end