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
Direct Known Subclasses
Luban::Deployment::Packages::Curl::Installer, Luban::Deployment::Packages::Gem::Installer, Luban::Deployment::Packages::Git::Installer, Luban::Deployment::Packages::Jemalloc::Installer, Luban::Deployment::Packages::Logrotate::Installer, Luban::Deployment::Packages::Openssl::Installer, Luban::Deployment::Packages::Popt::Installer, Luban::Deployment::Packages::Ruby::Installer, Luban::Deployment::Packages::Rubygems::Installer, Luban::Deployment::Packages::Yaml::Installer, Service::Installer
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'
- UncompressOptions =
{
".gz" => "-z", ".tgz" => "-z", ".taz" => "-z",
".Z" => "-Z", ".taZ" => "-Z",
".bz2" => "-j", ".tz2" => "-j", ".tbz2" => "-j", ".tbz" => "-j",
".lz" => "--lzip",
".lzma" => "--lzma", ".tlz" => "--lzma",
".lzo" => "--lzop",
".xz" => "J"
}
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
#package_bin_path, #package_install_path, #packages_path
#app_archives_path, #app_bin_path, #app_path, #app_tmp_path, #archived_logs_path, #archives_path, #current_app_path, #deployment_projects_path, #docker_root_path, #downloads_path, #env_path, #envrc_file, #packages_root_path, #project_path, #releases_root_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
#dockerize, #dockerized?, #env_name, #logrotate_count, #monitor_itself?, #monitorable?
#parameter
#has_base_packages?, #validate_for_docker_cert_path
#monitor_defined?, #process_monitor_via
#current_uid, #current_user, included
#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cleanup_files, #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, #version_match?, #with_clean_env
#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
39
40
41
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 39
def cached?
md5_matched?(src_cache_path, src_file_md5)
end
|
#cleanup_all ⇒ Object
122
123
124
125
126
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 122
def cleanup_all
cleanup_temp!
cleanup_logs!
update_result "Cleaned up temporary files in #{package_full_name} installation"
end
|
27
28
29
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 27
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
28
29
30
31
32
33
34
|
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 28
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
|
36
37
38
|
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 36
def default_configure_opts
@default_configure_opts ||= []
end
|
#deprecated? ⇒ Boolean
26
|
# File 'lib/luban/deployment/cli/package/installer/core.rb', line 26
def deprecated?; task.opts.deprecated; end
|
#download ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 48
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
35
36
37
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 35
def downloaded?
file?(src_file_path)
end
|
#get_summary ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 128
def get_summary
status = if current_symlinked?
current? ? " *" : "s*"
else
current? ? "c*" : (deprecated? ? " d" : " ")
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 66
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
31
32
33
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 31
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
21
22
23
24
25
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 21
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
17
18
19
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 17
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 88
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 = if deprecated?
"#{package_full_name} has been deprecated."
else
"#{package_full_name} is NOT installed."
end
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 153
def update_binstubs
return if child?
if current?
if installed?
update_binstubs!
update_result "Updated #{package_name} binstubs/symlinks 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/symlinks with version #{package_version}. " +
"Current version of #{package_name} is NOT specified.",
level: :warn
end
end
end
|
#validate_download_url ⇒ Object
43
44
45
46
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 43
def validate_download_url
info "Validating download URL for #{package_full_name}"
validate_download_url!
end
|
#whence_origin ⇒ Object
184
185
186
187
188
189
190
191
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 184
def whence_origin
get_summary.tap do |result|
result.summary[:executable] = "Not found"
if file?(executable = bin_path.join(task.args.executable))
result.summary[:executable] = executable
end
end
end
|
#which_current ⇒ Object
174
175
176
177
178
179
180
181
182
|
# File 'lib/luban/deployment/cli/package/installer/install.rb', line 174
def which_current
get_summary.tap do |result|
result.summary[:executable] = "Not found"
if current? and current_symlinked? and
file?(executable = File.join(readlink(current_path), 'bin', task.args.executable))
result.summary[:executable] = executable
end
end
end
|