-
Notifications
You must be signed in to change notification settings - Fork 900
/
Copy pathmiq_environment.rb
94 lines (77 loc) · 2.53 KB
/
miq_environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'sys-uname'
module MiqEnvironment
class Command
EVM_KNOWN_COMMANDS = %w[apachectl memcached memcached-tool nohup service systemctl].freeze
def self.supports_memcached?
return @supports_memcached unless @supports_memcached.nil?
@supports_memcached = is_linux? && is_appliance? && !is_container? && supports_command?('memcached') && supports_command?('memcached-tool') && supports_command?('service')
end
def self.supports_apache?
return @supports_apache unless @supports_apache.nil?
@supports_apache = is_appliance? && supports_command?('apachectl')
end
def self.supports_systemd?
return @supports_systemd unless @supports_systemd.nil?
@supports_systemd = is_appliance? && supports_command?('systemctl')
end
def self.supports_nohup_and_backgrounding?
return @supports_nohup unless @supports_nohup.nil?
@supports_nohup = is_appliance? && supports_command?('nohup')
end
def self.is_production_build?
is_appliance? || is_podified? || is_container?
end
def self.is_container?
return @is_container unless @is_container.nil?
@is_container = ENV["CONTAINER"] == "true"
end
def self.is_podified?
return @is_podified unless @is_podified.nil?
@is_podified = is_container? && ContainerOrchestrator.available?
end
def self.is_appliance?
return @is_appliance unless @is_appliance.nil?
@is_appliance = ENV["APPLIANCE"] == "true"
end
# Return whether or not the current ManageIQ environment is a production
# environment. Assumes production if Rails is not defined or if the Rails
# environment is set to 'production'.
#
def self.is_production?
defined?(Rails) ? Rails.env.production? : true
end
def self.is_linux?
return @is_linux unless @is_linux.nil?
@is_linux = (Sys::Platform::IMPL == :linux)
end
def self.rake_command
"rake"
end
def self.runner_command
"#{rails_command} runner"
end
def self.rails_command
"rails"
end
def self.supports_command?(cmd)
return false unless EVM_KNOWN_COMMANDS.include?(cmd)
require "runcmd"
begin
# If 'which apachectl' returns non-zero, it wasn't found
MiqUtil.runcmd(which, :params => [[cmd]])
rescue
false
else
true
end
end
def self.which
case Sys::Platform::IMPL
when :linux
"which"
else
raise "Not yet supported platform: #{Sys::Platform::IMPL}"
end
end
end
end