diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index f9f80e9..e645d1b 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -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 diff --git a/app/models/site_construct.rb b/app/models/site_construct.rb index 7361fc0..82f5d50 100644 --- a/app/models/site_construct.rb +++ b/app/models/site_construct.rb @@ -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 diff --git a/app/views/admin/site_panel/_form.html.erb b/app/views/admin/site_panel/_form.html.erb index b6b5801..77346e6 100644 --- a/app/views/admin/site_panel/_form.html.erb +++ b/app/views/admin/site_panel/_form.html.erb @@ -20,16 +20,23 @@
-
- <% copy_source = SiteConstruct.find(params[:copy_id]) rescue nil %> - <% if copy_source %> - - - <%= f.hidden_field :copy_id, :value => params[:copy_id] %> - <% end %> -
+ <% copy_source = SiteConstruct.find(params[:copy_id]) rescue nil %> + <% if copy_source %> +
+ + + <%= f.hidden_field :copy_id, :value => params[:copy_id] %> +
+
+ +
+ <%= f.check_box :only_copy_installed_module %> +
+ <%= f.hidden_field :copy_id, :value => params[:copy_id] %> +
+ <% end %>
<%= f.label :server_type ,"Server", :class => "control-label muted" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 04b4ae0..6af4856 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 338cd46..7ac4b6f 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,5 +1,6 @@ zh_tw: client_management: + only_copy_installed_module: 只複製安裝的模組 copy_source: 複製來源 see_sites: 查看主機上的網站 client_management: 網站管理系統 diff --git a/lib/tasks/copy_site.rake b/lib/tasks/copy_site.rake index e42de3e..5cd8011 100644 --- a/lib/tasks/copy_site.rake +++ b/lib/tasks/copy_site.rake @@ -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,21 +83,21 @@ 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) - - 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") - exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}") - exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx") - else - exec_ssh_command_by_sudo_for_create(ssh,"sshpass -p '#{server.password}' ssh #{server.account}@#{server.ip} 'mongodump -d #{template_site.db_name} -o #{template_site.path}/#{template_site.site_name}/dump_xxxx'") - exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/dump_xxxx/ #{args.path}/#{args.site_name}/dump_xxxx/") - exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}") - exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx") - 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'") + 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") + exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}") + exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx") + else + exec_ssh_command_by_sudo_for_create(ssh,"sshpass -p '#{server.password}' ssh #{server.account}@#{server.ip} 'mongodump -d #{template_site.db_name} -o #{template_site.path}/#{template_site.site_name}/dump_xxxx'") + exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/dump_xxxx/ #{args.path}/#{args.site_name}/dump_xxxx/") + exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}") + exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx") + 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("Finish copying database!") - update_infos("Checking extensions!") extensions = ["downloaded_extensions.rb","built_in_extensions.rb"] extensions.each do |extension_file|