diff --git a/waiting_queue.module b/waiting_queue.module
index 6dca4c4..686a5aa 100644
--- a/waiting_queue.module
+++ b/waiting_queue.module
@@ -1,5 +1,28 @@
 <?php
 
+class WaitingQueueSignalHandler {
+
+  protected $rebootRequired = FALSE;
+
+  protected $rebootSignals = array();
+
+  public function __construct(array $rebootSignals = array()) {
+    $this->rebootSignals = $rebootSignals;
+  }
+
+  public function rebootRequired() {
+    return $this->rebootRequired;
+  }
+
+  public function signalHandler($signalNumber) {
+    switch ($signalNumber) {
+      case SIGTERM:
+        $this->rebootRequired = TRUE;
+        break;
+    }
+  }
+}
+
 /**
  * Runs the named queue with no timeout.
  *
@@ -7,25 +30,35 @@
  *   Arbitrary string. The name of the queue to work with.
  */
 function waiting_queue_process_queue($queue_name) {
+  declare(ticks = 1);
   set_time_limit(0);
+
   $default_queue_process_lifetime = variable_get('waiting_queue_process_lifetime', 3600);
   $end_time = variable_get('waiting_queue_process_lifetime_' . $queue_name, $default_queue_process_lifetime) + time();
+  $default_reboot_signals = variable_get('waiting_queue_reboot_signals', array(SIGTERM));
+  $reboot_signals = variable_get('waiting_queue_reboot_signals_' . $queue_name, $default_reboot_signals);
 
   $queue = DrupalQueue::get($queue_name);
   $function = waiting_queue_get_callback_function($queue_name);
+  $signal_handler = new WaitingQueueSignalHandler($reboot_signals);
+
+  foreach ($reboot_signal as $signal_number) {
+    pcntl_signal($signal_number, array($signal_handler, 'signalHandler'));
+  }
 
   while (TRUE) {
     try {
       while ($item = $queue->claimItem()) {
-        if (time() < $end_time) {
-          // Only run the job if we haven't exceeded processing lifetime after claiming.
-          $function($item->data);
-          $queue->deleteItem($item);
-        }
-        else {
+        // The $queue->claimItem() call may block for a long time, so we check
+        // two things before processing a job: a) that we haven't exceeded the
+        // process lifetime, and b) whether a reboot is required.
+        if (time() > $end_time || $signal_handler->rebootRequired()) {
           $queue->releaseItem($item);
-          break 2;
+          exit();
         }
+
+        $function($item->data);
+        $queue->deleteItem($item);
       }
     }
     catch (Exception $e) {
@@ -38,6 +71,13 @@ function waiting_queue_process_queue($queue_name) {
         $queue->deleteItem($item);
       }
     }
+
+    // If we caught an error, or $queue->claimItem() didn't return a job, we
+    // can end up here, and it could be a long time since we last checked
+    // process lifetime or reboot flag, so check again.
+    if (time() > $end_time || $signal_handler->rebootRequired()) {
+      exit();
+    }
   }
 }
 
