Added ruby manager. Partial
This commit is contained in:
@@ -9,6 +9,7 @@ class EmptyWorker < Kernel::ModuleCoreWorker
|
||||
NAME: MODULE_ID,
|
||||
DESCR: "Just empty module for storing max module id",
|
||||
REQ: "",
|
||||
CONF: "",
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ class PassengerWorker < Kernel::ModuleCoreWorker
|
||||
NAME: MODULE_ID,
|
||||
DESCR: "Added passenger support for nginx",
|
||||
REQ: "puppet_installer",
|
||||
CONF: "yes",
|
||||
}
|
||||
end
|
||||
|
||||
@@ -28,6 +29,7 @@ class PassengerWorker < Kernel::ModuleCoreWorker
|
||||
"Req error, needed #{inf[:REQ]}"
|
||||
else
|
||||
begin
|
||||
prepare_default_ruby_conf
|
||||
log("install packages for passenger + nginx support: /usr/bin/puppet apply --detailed-exitcodes #{f_inst_pp}")
|
||||
result_action = `/usr/bin/puppet apply --detailed-exitcodes "#{f_inst_pp}"`
|
||||
ex_status = $?.exitstatus
|
||||
@@ -71,22 +73,73 @@ class PassengerWorker < Kernel::ModuleCoreWorker
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_default_ruby_conf()
|
||||
#TODO
|
||||
def prepare_default_ruby_conf
|
||||
ruby_conf_rubys = get_module_conf("rubys.conf")
|
||||
return if File.exist?(ruby_conf_rubys)
|
||||
|
||||
arr = ["/usr/bin/ruby", "/opt/brepo/ruby33/bin/ruby"]
|
||||
hestia_write_to_config_with_lock(ruby_conf_rubys, arr)
|
||||
end
|
||||
|
||||
def return_rubys_from_conf
|
||||
arr = []
|
||||
ruby_conf_rubys = get_module_conf("rubys.conf")
|
||||
return arr unless File.exist?(ruby_conf_rubys)
|
||||
|
||||
hestia_read_config_with_lock(ruby_conf_rubys)
|
||||
end
|
||||
|
||||
def command(args)
|
||||
if args.length < 1
|
||||
log("Not enough arguments. Needed command")
|
||||
"Not enough arguments. Needed command"
|
||||
end
|
||||
return log_return("Not enough arguments. Needed command") if args.length < 1
|
||||
|
||||
m_command = args[0].strip
|
||||
case m_command
|
||||
when "get_rubys"
|
||||
#TODO
|
||||
result = return_rubys_from_conf.map { |item| { "RUBY" => item } }
|
||||
format = (args[1].nil? ? "shell" : args[1].strip)
|
||||
hestia_print_array_of_hashes(result, format, "RUBY")
|
||||
ACTION_OK
|
||||
when "add_ruby"
|
||||
path = args[1]
|
||||
if path.nil?
|
||||
log_return("Path to ruby should be specified. #{args}")
|
||||
else
|
||||
path = path.strip
|
||||
if File.exist?(path)
|
||||
rubys = return_rubys_from_conf
|
||||
unless rubys.include? path
|
||||
rubys << path
|
||||
ruby_conf_rubys = get_module_conf("rubys.conf")
|
||||
hestia_write_to_config_with_lock(ruby_conf_rubys, rubys)
|
||||
end
|
||||
ACTION_OK
|
||||
else
|
||||
log_return("File #{path} doesn't exists")
|
||||
end
|
||||
end
|
||||
when "del_ruby"
|
||||
path = args[1]
|
||||
if path.nil?
|
||||
log_return("Path to ruby should be specified. #{args}")
|
||||
else
|
||||
path = path.strip
|
||||
rubys = return_rubys_from_conf
|
||||
if rubys.include? path
|
||||
rubys.delete(path)
|
||||
ruby_conf_rubys = get_module_conf("rubys.conf")
|
||||
hestia_write_to_config_with_lock(ruby_conf_rubys, rubys)
|
||||
end
|
||||
ACTION_OK
|
||||
end
|
||||
when "set_user_ruby"
|
||||
domain = args[1]
|
||||
if domain.nil?
|
||||
log_return("Domain should be specified. #{args}")
|
||||
else
|
||||
#TODO
|
||||
end
|
||||
else
|
||||
log("Unknown commands. #{args}")
|
||||
"Unknown commands. #{args}"
|
||||
log_return("Unknown commands. #{args}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class PuppetWorker < Kernel::ModuleCoreWorker
|
||||
NAME: MODULE_ID,
|
||||
DESCR: "Added puppet support, needed for another modules",
|
||||
REQ: "",
|
||||
CONF: "",
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -228,3 +228,21 @@ def hestia_print_array_of_hashes(in_array = nil, format = "shell", header = nil)
|
||||
hestia_format_cli_table(data_out)
|
||||
end
|
||||
end
|
||||
|
||||
def hestia_write_to_config_with_lock(config_file, values, perms = 0600)
|
||||
File.open(config_file, File::WRONLY | File::CREAT, perms) do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
f.truncate(0)
|
||||
values.each { |item| f.puts(item) }
|
||||
f.flush
|
||||
end
|
||||
end
|
||||
|
||||
def hestia_read_config_with_lock(config_file)
|
||||
arr = []
|
||||
File.open(config_file, File::RDONLY) do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
f.each { |line| arr << line.strip }
|
||||
end
|
||||
arr
|
||||
end
|
||||
|
||||
@@ -101,6 +101,11 @@ class Kernel::ModuleCoreWorker
|
||||
File.append! log_file, "#{log_time} #{out_result}"
|
||||
end
|
||||
|
||||
def log_return(format, *args)
|
||||
log(format, *args)
|
||||
format % args
|
||||
end
|
||||
|
||||
def check
|
||||
result = self.info
|
||||
if result[:REQ] == "" || result[:REQ].nil?
|
||||
|
||||
Reference in New Issue
Block a user