Add "only copy installed modules" feature.
This commit is contained in:
parent
bc631ffd59
commit
fd8ee8bd0e
|
@ -105,7 +105,7 @@ class Admin::SitePanelController < OrbitAdminController
|
|||
end
|
||||
else
|
||||
Thread.new do
|
||||
system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{params[:site_construct][:copy_id]}']")
|
||||
system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{params[:site_construct][:copy_id]}',#{site_construct.only_copy_installed_module}]")
|
||||
end
|
||||
end
|
||||
redirect_to "#{admin_site_panel_sites_list_path}?id=#{site_construct_id}"
|
||||
|
@ -128,7 +128,7 @@ class Admin::SitePanelController < OrbitAdminController
|
|||
site_construct_id = params[:id]
|
||||
if site_construct.copy_id
|
||||
Thread.new do
|
||||
system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{site_construct.copy_id}']")
|
||||
system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{site_construct.copy_id}',#{site_construct.only_copy_installed_module}]")
|
||||
end
|
||||
else
|
||||
Thread.new do
|
||||
|
|
|
@ -21,7 +21,7 @@ class SiteConstruct
|
|||
field :infos, type: Array, :default => []
|
||||
field :hidden, type: Boolean, :default => false
|
||||
field :copy_id
|
||||
|
||||
field :only_copy_installed_module, type: Boolean, :default => false
|
||||
field :cert_ver_added_text
|
||||
field :cert_ver_file_content
|
||||
field :cert_ver_location_path
|
||||
|
|
|
@ -20,16 +20,23 @@
|
|||
<div class="tab-content module-area">
|
||||
<!-- Basic Module -->
|
||||
<div class="tab-pane fade in active" id="basic">
|
||||
<div class="control-group">
|
||||
<% copy_source = SiteConstruct.find(params[:copy_id]) rescue nil %>
|
||||
<% if copy_source %>
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("client_management.copy_source") %></label>
|
||||
<div class="controls">
|
||||
<a title="<%= copy_source.site_name %>" href="<%= copy_source.get_domain_name %>" style="font-weight: bold; font-size: 1.3em;"><%= copy_source.site_name %></a>
|
||||
</div>
|
||||
<%= f.hidden_field :copy_id, :value => params[:copy_id] %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("client_management.only_copy_installed_module") %></label>
|
||||
<div class="controls">
|
||||
<%= f.check_box :only_copy_installed_module %>
|
||||
</div>
|
||||
<%= f.hidden_field :copy_id, :value => params[:copy_id] %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="control-group">
|
||||
<%= f.label :server_type ,"Server", :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
en:
|
||||
client_management:
|
||||
only_copy_installed_module: Only copy installed modules
|
||||
copy_source: Copy Source
|
||||
see_sites: See sites on the server
|
||||
client_management: Client Management
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
zh_tw:
|
||||
client_management:
|
||||
only_copy_installed_module: 只複製安裝的模組
|
||||
copy_source: 複製來源
|
||||
see_sites: 查看主機上的網站
|
||||
client_management: 網站管理系統
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'net/ssh'
|
|||
require 'pathname'
|
||||
namespace :create_site do
|
||||
desc "Copy Site from another site"
|
||||
task :copy_site,[:ip,:user,:password,:site_name,:domain_name,:port,:db_name,:path,:site_construct_id,:template_site_construct_id] => :environment do |task,args|
|
||||
task :copy_site,[:ip,:user,:password,:site_name,:domain_name,:port,:db_name,:path,:site_construct_id,:template_site_construct_id,:only_copy_installed_module] => :environment do |task,args|
|
||||
@password = args.password
|
||||
template_site = SiteConstruct.find(args.template_site_construct_id)
|
||||
if args.site_construct_id.blank?
|
||||
|
@ -60,16 +60,20 @@ namespace :create_site do
|
|||
|
||||
update_infos("copying site's files for #{args.site_name}")
|
||||
exec_ssh_command_for_create(ssh,"sudo -p 'sudo password:' apt-get install -y rsync")
|
||||
extra_exclude_path = ""
|
||||
if args.only_copy_installed_module == true || args.only_copy_installed_module == "true"
|
||||
extra_exclude_path = ",public/uploads/"
|
||||
end
|
||||
if @site_construct.server_type == template_site.server_type
|
||||
exec_ssh_command_for_create(ssh,"rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*} #{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
|
||||
exec_ssh_command_for_create(ssh,"rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*#{extra_exclude_path}} #{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
|
||||
else
|
||||
server = SiteServer.where(:server_name => template_site.server_type).first
|
||||
exec_ssh_command_for_create(ssh,"sudo -p 'sudo password:' apt-get install -y sshpass")
|
||||
outputs = exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
|
||||
outputs = exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*#{extra_exclude_path}} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
|
||||
if outputs.join("\n").include?("Host key verification failed")
|
||||
exec_ssh_command_by_sudo_for_create(ssh,"ssh-keygen -f \"$HOME/.ssh/known_hosts\" -R #{server.ip}")
|
||||
exec_ssh_command_by_sudo_for_create(ssh,"ssh-keyscan -H #{server.ip} >> ~/.ssh/known_hosts")
|
||||
exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
|
||||
exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*#{extra_exclude_path}} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
|
||||
end
|
||||
end
|
||||
update_infos("Finish copying site's files for #{args.site_name}!")
|
||||
|
@ -79,7 +83,7 @@ namespace :create_site do
|
|||
db_setting_text = ssh.exec!("cat #{args.path}/#{args.site_name}/config/mongoid.yml")
|
||||
update_infos("setting dbname to #{args.db_name}")
|
||||
exec_ssh_command_by_sudo_for_create(ssh,"sh -c \"echo '#{db_setting_text.gsub(template_site.db_name,args.db_name)}' > #{args.path}/#{@site_construct.get_site_name}/config/mongoid.yml\"",true)
|
||||
|
||||
unless args.only_copy_installed_module == true || args.only_copy_installed_module == "true"
|
||||
update_infos("copying db from #{template_site.db_name} to #{args.db_name}")
|
||||
if @site_construct.server_type == template_site.server_type
|
||||
exec_ssh_command_by_sudo_for_create(ssh,"mongodump -d #{template_site.db_name} -o #{args.path}/#{@site_construct.get_site_name}/dump_xxxx")
|
||||
|
@ -93,7 +97,7 @@ namespace :create_site do
|
|||
exec_ssh_command_by_sudo_for_create(ssh,"sshpass -p '#{server.password}' ssh #{server.account}@#{server.ip} 'rm -rf #{template_site.path}/#{template_site.get_site_name}/dump_xxxx'")
|
||||
end
|
||||
update_infos("Finish copying database!")
|
||||
|
||||
end
|
||||
update_infos("Checking extensions!")
|
||||
extensions = ["downloaded_extensions.rb","built_in_extensions.rb"]
|
||||
extensions.each do |extension_file|
|
||||
|
|
Loading…
Reference in New Issue