From 4905975d79f565a7fb64ed04d0af0ef9d342aa7f Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Mon, 9 Dec 2024 23:55:35 +0300 Subject: [PATCH] Added ruby manager. Partial --- bin/v-ext-modules | 2 +- bin/v-ext-modules-run | 0 func_ruby/ext-modules/empty_module.mod | 1 + func_ruby/ext-modules/passenger_manager.mod | 71 ++++++++++++++++++--- func_ruby/ext-modules/puppet_installer.mod | 1 + func_ruby/main.rb | 18 ++++++ func_ruby/modules.rb | 5 ++ web/extm/passenger_manger/edit/index.php | 24 +++++++ web/templates/pages/extmodules.php | 19 +++++- 9 files changed, 130 insertions(+), 11 deletions(-) mode change 100644 => 100755 bin/v-ext-modules-run diff --git a/bin/v-ext-modules b/bin/v-ext-modules index e2ccbdc..7cfff72 100755 --- a/bin/v-ext-modules +++ b/bin/v-ext-modules @@ -88,7 +88,7 @@ when :list, :state else format = (v_ext_option.nil? ? "shell" : v_ext_option.strip) end - hestia_print_array_of_hashes(result_arr, format, "ID, NAME, DESCR, STATE, REQ") + hestia_print_array_of_hashes(result_arr, format, "ID, NAME, DESCR, STATE, REQ, CONF") when :enable if v_ext_option.nil? hestia_print_error_message_to_cli "no module name specified" diff --git a/bin/v-ext-modules-run b/bin/v-ext-modules-run old mode 100644 new mode 100755 diff --git a/func_ruby/ext-modules/empty_module.mod b/func_ruby/ext-modules/empty_module.mod index 5379d37..1ada134 100644 --- a/func_ruby/ext-modules/empty_module.mod +++ b/func_ruby/ext-modules/empty_module.mod @@ -9,6 +9,7 @@ class EmptyWorker < Kernel::ModuleCoreWorker NAME: MODULE_ID, DESCR: "Just empty module for storing max module id", REQ: "", + CONF: "", } end diff --git a/func_ruby/ext-modules/passenger_manager.mod b/func_ruby/ext-modules/passenger_manager.mod index 962ca2b..4dd197b 100644 --- a/func_ruby/ext-modules/passenger_manager.mod +++ b/func_ruby/ext-modules/passenger_manager.mod @@ -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 diff --git a/func_ruby/ext-modules/puppet_installer.mod b/func_ruby/ext-modules/puppet_installer.mod index b81ebde..c971801 100644 --- a/func_ruby/ext-modules/puppet_installer.mod +++ b/func_ruby/ext-modules/puppet_installer.mod @@ -12,6 +12,7 @@ class PuppetWorker < Kernel::ModuleCoreWorker NAME: MODULE_ID, DESCR: "Added puppet support, needed for another modules", REQ: "", + CONF: "", } end diff --git a/func_ruby/main.rb b/func_ruby/main.rb index 896a4ce..24f08a5 100644 --- a/func_ruby/main.rb +++ b/func_ruby/main.rb @@ -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 diff --git a/func_ruby/modules.rb b/func_ruby/modules.rb index 59006cc..1903694 100644 --- a/func_ruby/modules.rb +++ b/func_ruby/modules.rb @@ -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? diff --git a/web/extm/passenger_manger/edit/index.php b/web/extm/passenger_manger/edit/index.php index e69de29..875d328 100644 --- a/web/extm/passenger_manger/edit/index.php +++ b/web/extm/passenger_manger/edit/index.php @@ -0,0 +1,24 @@ +
+
@@ -81,10 +82,26 @@ : -
+
:
+
+ : + + + + + +   + +