mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FIX: Killing a Unicorn worker shouldn't kill a running backup or restore process
By spawning and forking the backup and restore, the process owner changes from 🦄 to the init process.
This commit is contained in:
parent
1febf11362
commit
57095f0bb7
|
@ -172,9 +172,9 @@ module BackupRestore
|
||||||
|
|
||||||
def self.spawn_process!(type, user_id, opts)
|
def self.spawn_process!(type, user_id, opts)
|
||||||
script = File.join(Rails.root, "script", "spawn_backup_restore.rb")
|
script = File.join(Rails.root, "script", "spawn_backup_restore.rb")
|
||||||
command = ["bundle", "exec", "ruby", script, type, user_id, opts.to_json].shelljoin
|
command = ["bundle", "exec", "ruby", script, type, user_id, opts.to_json].map(&:to_s)
|
||||||
|
|
||||||
pid = spawn({ "RAILS_DB" => RailsMultisite::ConnectionManagement.current_db }, command)
|
pid = spawn({ "RAILS_DB" => RailsMultisite::ConnectionManagement.current_db }, *command)
|
||||||
Process.detach(pid)
|
Process.detach(pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,40 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
# This script is used by BackupRestore.backup! and BackupRestore.restore!
|
# This script is used by BackupRestore.backup! and BackupRestore.restore!
|
||||||
|
|
||||||
require File.expand_path("../../config/environment", __FILE__)
|
fork do
|
||||||
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
|
|
||||||
def backup
|
def backup
|
||||||
user_id, opts = parse_params
|
user_id, opts = parse_params
|
||||||
BackupRestore::Backuper.new(user_id, opts).run
|
BackupRestore::Backuper.new(user_id, opts).run
|
||||||
end
|
end
|
||||||
|
|
||||||
def restore
|
def restore
|
||||||
user_id, opts = parse_params
|
user_id, opts = parse_params
|
||||||
|
|
||||||
BackupRestore::Restorer.new(
|
BackupRestore::Restorer.new(
|
||||||
user_id: user_id,
|
|
||||||
filename: opts[:filename],
|
|
||||||
factory: BackupRestore::Factory.new(
|
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
client_id: opts[:client_id]
|
filename: opts[:filename],
|
||||||
),
|
factory: BackupRestore::Factory.new(
|
||||||
disable_emails: opts.fetch(:disable_emails, true)
|
user_id: user_id,
|
||||||
).run
|
client_id: opts[:client_id]
|
||||||
end
|
),
|
||||||
|
disable_emails: opts.fetch(:disable_emails, true)
|
||||||
|
).run
|
||||||
|
end
|
||||||
|
|
||||||
def parse_params
|
def parse_params
|
||||||
user_id = ARGV[1].to_i
|
user_id = ARGV[1].to_i
|
||||||
opts = JSON.parse(ARGV[2], symbolize_names: true)
|
opts = JSON.parse(ARGV[2], symbolize_names: true)
|
||||||
[user_id, opts]
|
[user_id, opts]
|
||||||
end
|
end
|
||||||
|
|
||||||
case ARGV[0]
|
case ARGV[0]
|
||||||
when "backup"
|
when "backup"
|
||||||
backup
|
backup
|
||||||
when "restore"
|
when "restore"
|
||||||
restore
|
restore
|
||||||
else
|
else
|
||||||
raise "Unknown argument: #{ARGV[0]}"
|
raise "Unknown argument: #{ARGV[0]}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user