|
|
|
@ -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|
|
|
|
|
|