This commit is contained in:
BoHung Chiu 2022-10-16 16:43:14 +08:00
parent d26b93d039
commit a27f26bfc1
2 changed files with 11 additions and 3 deletions

View File

@ -338,11 +338,13 @@ class Admin::SitePanelController < OrbitAdminController
idx = cmds.index('{{create_super_manager}}')
cmds[idx] = create_super_manager_cmd(params[:account],params[:password])
end
exec_commands_args = {}
if params[:id].blank? && !params[:server_names].blank?
Rake::Task['exec_commands:exec_commands'].execute(Rake::TaskArguments.new([:commands, :type, :server_name], [cmds.join('////'), 'exec_all', params[:server_names].join('////')]))
exec_commands_args = {:commands=>cmds.join('////'), :type=>'exec_all', :server_name=>params[:server_names].join('////')}
else
Rake::Task['exec_commands:exec_commands'].execute(Rake::TaskArguments.new([:site_construct_id, :commands, :type], [params[:id], cmds.join('////'), 'exec_commands']))
exec_commands_args = {:site_construct_id=>params[:id], :commands=>cmds.join('////'), :type=>'exec_commands'}
end
system("bundle exec rake exec_commands:exec_commands[\"#{Base64.strict_encode64(exec_commands_args.to_json)}\"]")
end
end
render :json =>{"success"=>true}

View File

@ -1,8 +1,14 @@
require 'net/ssh'
require 'pathname'
require 'json'
require 'base64'
namespace :exec_commands do
desc "Exec commands Script"
task :exec_commands,[:site_construct_id,:commands,:type,:server_name,:rails_env] => :environment do |task,args|
task :exec_commands,[:base64_args,:site_construct_id,:commands,:type,:server_name,:rails_env] => :environment do |task,args|
if args.base64_args.present?
tmp = JSON.parse(Base64.decode64(args.base64_args)) rescue {}
args = Rake::TaskArguments.new(tmp.keys, tmp.values)
end
@type = args.type
if !args.site_construct_id.blank?
@site_construct = SiteConstruct.find(args.site_construct_id)