forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiq_environment.rb
73 lines (60 loc) · 1.95 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
require 'sys-uname'
module MiqEnvironment
class Command
EVM_KNOWN_COMMANDS = %w( memcached memcached-tool service apachectl nohup)
def self.supports_memcached?
return @supports_memcached unless @supports_memcached.nil?
@supports_memcached = self.is_linux? && self.is_appliance? && self.supports_command?('memcached') && self.supports_command?('memcached-tool') && self.supports_command?('service')
end
def self.supports_apache?
return @supports_apache unless @supports_apache.nil?
@supports_apache = self.is_appliance? && self.supports_command?('apachectl')
end
def self.supports_nohup_and_backgrounding?
return @supports_nohup unless @supports_nohup.nil?
@supports_nohup = self.is_appliance? && self.supports_command?('nohup')
end
def self.is_appliance?
return @is_appliance unless @is_appliance.nil?
@is_appliance = self.is_linux? && File.exist?('/var/www/miq/vmdb')
end
def self.is_production?
# Note: This method could be called outside of Rails, so check defined?(Rails)
# Assume production if not defined or if set to '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} #{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