You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hestiacp/func_ruby/ext-modules/passenger_manager.mod

109 lines
2.9 KiB

#!/opt/brepo/ruby33/bin/ruby
require "shell"
class PassengerWorker < Kernel::ModuleCoreWorker
MODULE_ID = "passenger_manager"
def check_domains_with_passenger
true
end
def info
{
ID: 2,
NAME: MODULE_ID,
DESCR: "Added passenger support for nginx",
REQ: "puppet_installer",
}
end
def enable
log_file = get_log
f_inst_pp = get_module_paydata("passenger_installer.pp")
f_uninst_pp = get_module_paydata("passenger_uninstaller.pp")
if !check
inf = info
log("Req error, needed #{inf[:REQ]}")
"Req error, needed #{inf[:REQ]}"
else
begin
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
if ex_status.to_i == 0 || ex_status.to_i == 2
log(result_action)
super
else
log(result_action)
log("Try to disable action: /usr/bin/puppet apply --detailed-exitcodes #{f_uninst_pp}")
result_action = `/usr/bin/puppet apply --detailed-exitcodes "#{f_uninst_pp}"`
"module installation error. See log #{log_file}"
end
rescue => e
log("module installation error #{e.message} #{e.backtrace.first}")
"module installation error. See log #{log_file}"
end
end
end
def disable
log_file = get_log
f_uninst_pp = get_module_paydata("passenger_uninstaller.pp")
if !check_domains_with_passenger
return "Presents domains with passenger support disable it first"
end
begin
log("uninstall packages for passenger + nginx support")
log("Try to disable action: /usr/bin/puppet apply --detailed-exitcodes #{f_uninst_pp}")
result_action = `/usr/bin/puppet apply --detailed-exitcodes "#{f_uninst_pp}"`
ex_status = $?.exitstatus
if ex_status.to_i == 0 || ex_status.to_i == 2
log(result_action)
super
else
log(result_action)
"module installation error. See log #{log_file}"
end
rescue => e
log("module installation error #{e.message} #{e.backtrace.first}")
"module installation error. See log #{log_file}"
end
end
def prepare_default_ruby_conf()
#TODO
end
def command(args)
if args.length < 1
log("Not enough arguments. Needed command")
"Not enough arguments. Needed command"
end
m_command = args[0].strip
case m_command
when "get_rubys"
#TODO
else
log("Unknown commands. #{args}")
"Unknown commands. #{args}"
end
end
implements IPluginInterface
end
module PassengerModule
def get_object
Proc.new { PassengerWorker.new }
end
module_function :get_object
end
class Kernel::PluginConfiguration
include PassengerModule
@@loaded_plugins[PassengerWorker::MODULE_ID] = PassengerModule.get_object
end