FIX: Backup didn't work anymore after a running backup was canceled

FIX: Backup didn’t work anymore after a running backup was canceled

diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb
index 8f00090..dea11cd 100644
--- a/lib/backup_restore/backuper.rb
+++ b/lib/backup_restore/backuper.rb
@@ -96,6 +96,8 @@ module BackupRestore
     end
 
     def listen_for_shutdown_signal
+      BackupRestore.clear_shutdown_signal!
+
       Thread.new do
         while BackupRestore.is_operation_running?
           exit if BackupRestore.should_shutdown?
diff --git a/lib/backup_restore/system_interface.rb b/lib/backup_restore/system_interface.rb
index 2ed9513..fec6735 100644
--- a/lib/backup_restore/system_interface.rb
+++ b/lib/backup_restore/system_interface.rb
@@ -44,6 +44,8 @@ module BackupRestore
     end
 
     def listen_for_shutdown_signal
+      BackupRestore.clear_shutdown_signal!
+
       Thread.new do
         while BackupRestore.is_operation_running?
           exit if BackupRestore.should_shutdown?
diff --git a/spec/lib/backup_restore/system_interface_spec.rb b/spec/lib/backup_restore/system_interface_spec.rb
index a2a2c43..d75de32 100644
--- a/spec/lib/backup_restore/system_interface_spec.rb
+++ b/spec/lib/backup_restore/system_interface_spec.rb
@@ -69,6 +69,15 @@ describe BackupRestore::SystemInterface do
         thread.join
       end.to raise_error(SystemExit)
     end
+
+    it "clears an existing shutdown signal before it starts to listen" do
+      BackupRestore.set_shutdown_signal!
+      expect(BackupRestore.should_shutdown?).to eq(true)
+
+      thread = subject.listen_for_shutdown_signal
+      expect(BackupRestore.should_shutdown?).to eq(false)
+      Thread.kill(thread)
+    end
   end
 
   describe "#pause_sidekiq" do

GitHub sha: 1febf113

This commit appears in #10909 which was approved by eviltrout. It was merged by gschlager.