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', Darwin: 'dylib' }
- DefaultLibExtension =
'so'
- DefaultSrcFileExtName =
'tar.gz'
Luban::Deployment::Parameters::Application::DefaultLogrotateInterval, Luban::Deployment::Parameters::Application::DefaultLogrotateMaxAge
Luban::Deployment::Parameters::General::DefaultLubanRootPath
Helpers::Utils::LogLevels
Instance Attribute Summary collapse
Attributes inherited from Worker::Base
#task
#backend
#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
#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
#dry_run?, #force?, #initialize, #linux?, #method_missing, #osx?, #packages, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version
#env_name, #logrotate_count, #monitor_itself?, #monitorable?
#parameter
#monitor_defined?, #process_monitor_via
included
#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
#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?
Instance Attribute Details
#build_env_vars ⇒ Object
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
|
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_path ⇒ Object
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
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_all ⇒ Object
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
|
17
18
19
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 17
def configure_executable
@configure_executable ||= './configure'
end
|
23
|
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 23
def current_configured?; task.opts.current; end
|
#current_package_version ⇒ Object
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
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_by ⇒ Object
15
16
17
|
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 15
def currently_used_by
parent.currently_used_by
end
|
34
35
36
|
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 34
def default_configure_opts
@default_configure_opts ||= []
end
|
#download ⇒ Object
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_url ⇒ Object
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
25
26
27
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 25
def downloaded?
file?(src_file_path)
end
|
#get_summary ⇒ Object
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_path ⇒ Object
43
44
45
|
# File 'lib/luban/deployment/cli/package/installer/paths.rb', line 43
def include_path
@include_path ||= install_path.join('include')
end
|
#install ⇒ Object
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_name ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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
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_path ⇒ Object
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_packages ⇒ Object
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_repo ⇒ Object
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_root ⇒ Object
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_path ⇒ Object
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_extname ⇒ Object
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_md5 ⇒ Object
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_name ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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
|
#uninstall ⇒ Object
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_binstubs ⇒ Object
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_url ⇒ Object
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_origin ⇒ Object
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_current ⇒ Object
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
|