try
This commit is contained in:
parent
202d2ba643
commit
a70a22d436
|
@ -134,7 +134,7 @@ class Admin::SitesController < OrbitAdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_update_history
|
def get_update_history
|
||||||
@update_log = %x{git log --pretty=format:"%ad','%s" --date=short}.split("\n").map{|log| log.gsub("'","").split(",")}.to_json
|
@update_log = %x{git log --pretty=format:"%H','%ad','%s" --date=short}.split("\n").map{|log| log.gsub("'","").split(",")}.to_json
|
||||||
render :json => @update_log
|
render :json => @update_log
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,41 +143,61 @@ class Admin::SitesController < OrbitAdminController
|
||||||
@new_updates = %x(git log #{@branch}..origin/#{@branch} --pretty=format:"%ad','%s" --date=short).split("\n").map{|log| log.gsub("'","").split(",")}.to_json
|
@new_updates = %x(git log #{@branch}..origin/#{@branch} --pretty=format:"%ad','%s" --date=short).split("\n").map{|log| log.gsub("'","").split(",")}.to_json
|
||||||
render :json => @new_updates
|
render :json => @new_updates
|
||||||
end
|
end
|
||||||
|
def git_reset(commit,type)
|
||||||
|
mul = Multithread.where(key: 'update_manager').first
|
||||||
|
mul = Multithread.create(key: 'update_manager') if mul.nil?
|
||||||
|
mul.update_attributes(status: 'waiting')
|
||||||
|
Thread.new do
|
||||||
|
ubuntu_version = %x[lsb_release -a | grep Release].scan(/\d.*\d/)[0]
|
||||||
|
git = 'git'
|
||||||
|
if Float(ubuntu_version) <= 14.04 && Float(%x[git --version].scan(/\d.\d/)[0]) < 1.9
|
||||||
|
if %x[uname -m].scan('64').count !=0
|
||||||
|
cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_amd64.deb && dpkg -x git_1.9.1-1_amd64.deb ./git_1.9.1")
|
||||||
|
else
|
||||||
|
cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_i386.deb && dpkg -x git_1.9.1-1_i386.deb ./git_1.9.1")
|
||||||
|
end
|
||||||
|
git = 'git_1.9.1/usr/bin/git'
|
||||||
|
end
|
||||||
|
git_add_except_public = Dir['*'].select{|v| v!= 'public'}.collect do |v|
|
||||||
|
"#{git} add -f '#{v}'"
|
||||||
|
end.join(' && ')
|
||||||
|
git_add_all_program = (Dir['app/*'].select{|v| !v.include? 'templates'} + Dir['lib/*'] + Dir['config/*'].select{|v| !v.include? 'mongoid.yml'}).collect do |v|
|
||||||
|
"#{git} add -f '#{v}'"
|
||||||
|
end.join(' && ')
|
||||||
|
time_now = Time.now.strftime('%Y_%m_%d_%H_%M')
|
||||||
|
Bundler.with_clean_env{system("#{git_add_except_public} && #{git} commit -m auto_backup_before_#{type}_#{time_now} && #{git} reset #{commit} --mixed && #{git_add_all_program} && #{git} reset #{commit} --merge && #{git} commit -m complete_#{type}_#{time_now}")}
|
||||||
|
mul.update_attributes(status: 'finish')
|
||||||
|
end
|
||||||
|
end
|
||||||
def update_orbit
|
def update_orbit
|
||||||
store_permissions = check_store_permissions
|
store_permissions = check_store_permissions
|
||||||
if store_permissions["permission_granted"]
|
if params['type'] == 'update'
|
||||||
result = ""
|
if store_permissions["permission_granted"]
|
||||||
need_stash = %x(git diff).blank?
|
git_reset('origin','update')
|
||||||
%x(git stash) unless need_stash
|
render :text => 'waiting'
|
||||||
%x(git fetch origin)
|
|
||||||
pull_result = %x(git pull -r --ff-only 2>&1 origin #{@branch})
|
|
||||||
%x(git stash pop) unless need_stash
|
|
||||||
|
|
||||||
if pull_result.include? "fatal: Not possible to fast-forward, aborting."
|
|
||||||
result = "failed"
|
|
||||||
else
|
else
|
||||||
result = "success"
|
render :json => store_permissions.to_json
|
||||||
# Bundler.with_clean_env { `cd #{Rails.root} && bundle update` }
|
|
||||||
end
|
end
|
||||||
|
elsif params['type'] == 'restore'
|
||||||
render :text => result
|
git_reset(params['id'],'restore')
|
||||||
else
|
render :text => 'waiting'
|
||||||
render :json => store_permissions.to_json
|
elsif params['type'] == 'get_result'
|
||||||
|
render :text => Multithread.where(key: 'update_manager').first.status rescue 'running'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bundle_install
|
def bundle_install
|
||||||
Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=built_in_extensions.rb bundle update && bundle` }
|
Bundler.with_clean_env { system("cd #{Rails.root} && bundle update") }
|
||||||
Bundler.with_clean_env { `cd #{Rails.root} && BUNDLE_GEMFILE=downloaded_extensions.rb bundle update && bundle` }
|
|
||||||
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
|
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
|
||||||
sleep 5
|
sleep 2
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
def restart_server
|
def restart_server
|
||||||
%x(kill -s USR2 `cat tmp/pids/unicorn.pid`)
|
mode = Rails.env
|
||||||
sleep 5
|
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
|
||||||
|
Bundler.with_clean_env{system("kill -s TERM `cat tmp/pids/unicorn.pid` && unset UNICORN_FD && bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}")}
|
||||||
|
sleep 2
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue