diff --git a/lib/tasks/copy_site.rake b/lib/tasks/copy_site.rake index 6a85383..e9fc626 100644 --- a/lib/tasks/copy_site.rake +++ b/lib/tasks/copy_site.rake @@ -47,16 +47,19 @@ namespace :create_site do extra_exclude_path = ",public/uploads/" end server = SiteServer.where(:server_name => template_site.server_type).first - 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/*#{extra_exclude_path}} #{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true) - else - 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/*#{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/*#{extra_exclude_path}} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true) - end + ls_out = exec_ssh_command_for_create(ssh, "ls #{@site_construct.full_site_path}/app").join("\n") + if ls_out.include?("No such") + 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/*#{extra_exclude_path}} #{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true) + else + 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/*#{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/*#{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 end update_infos("Finish copying site's files for #{args.site_name}!") diff --git a/lib/tasks/exec_command.rake b/lib/tasks/exec_command.rake index 1db901e..e1f1807 100644 --- a/lib/tasks/exec_command.rake +++ b/lib/tasks/exec_command.rake @@ -97,10 +97,10 @@ namespace :exec_commands do sites = [@site_construct] end if args.commands.include?("{{create_users}}") - commands = ['sudo -p "sudo password:" chmod 700 {{full_site_path}} -R', - 'sudo -p "sudo password:" chmod 755 {{full_site_path}}/public -R' - 'sudo -p "sudo password:" chmod 755 {{full_site_path}}/app/templates -R' - 'sudo -p "sudo password:" useradd --home-dir {{full_site_path}}/app/templates {{site_name}} --no-create-home --badnames' + commands = ['sudo -p "sudo password:" chmod 777 {{full_site_path}} -R', + 'sudo -p "sudo password:" chmod 777 {{full_site_path}}/public -R', + 'sudo -p "sudo password:" chmod 777 {{full_site_path}}/app/templates -R', + 'sudo -p "sudo password:" useradd --home-dir {{full_site_path}}/app/templates {{site_name}} --no-create-home --badnames', 'sudo -p "sudo password:" bash -l -c \'echo -e "{{site_name}}\n{{site_name}}"|passwd {{site_name}}\''] else commands = args.commands.split("////").select{|c| c != ""} rescue [args.commands]