]> www.vanbest.org Git - motioneye-debian/commitdiff
improved suprocess handling
authorCalin Crisan <ccrisan@gmail.com>
Sun, 6 Jul 2014 12:55:19 +0000 (15:55 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 6 Jul 2014 12:55:19 +0000 (15:55 +0300)
src/cleanup.py
src/thumbnailer.py
src/update.py

index aa1aef242fbdba6a1a75bc1da67502030d20576c..6e3a882e072e1dc63ce580ee6d3f3e2a3ba0c742 100644 (file)
@@ -44,6 +44,8 @@ def stop():
     
     if _process.is_alive():
         _process.join(timeout=10)
+    
+    if _process.is_alive():
         logging.error('cleanup process did not finish in time, killing it...')
         os.kill(_process.pid, signal.SIGKILL)
     
index 07831770d5befef229a69595a0d8401ffab74d28..1c8fded6b4ebd77239a231f7863c41a2feda05c0 100644 (file)
@@ -44,9 +44,11 @@ def stop():
     
     if _process.is_alive():
         _process.join(timeout=10)
+    
+    if _process.is_alive():
         logging.error('thumbnailer process did not finish in time, killing it...')
         os.kill(_process.pid, signal.SIGKILL)
-    
+
     _process = None
 
 
index e053635e516199819bed4a3069a38eed9c0523e3..cbf822558eab704e8c557cf262b34cee832a5f65 100644 (file)
@@ -20,6 +20,7 @@ import json
 import logging
 import os.path
 import shutil
+import signal
 import subprocess
 import tempfile
 import time
@@ -150,9 +151,10 @@ def perform_update(version):
     
     try:
         # make sure the partition where motionEye resides is writable
+        path = os.path.abspath(settings.PROJECT_PATH)
         if settings.ENABLE_REBOOT:
             try:
-                df_lines = subprocess.check_output('df %s' % settings.PROJECT_PATH, shell=True).split('\n')
+                df_lines = subprocess.check_output('df %s' % path, shell=True).split('\n')
                 last_line = [l for l in df_lines if l.strip()][-1]
                 mount_point = last_line.split()[-1]
                 
@@ -161,8 +163,8 @@ def perform_update(version):
             except Exception as e:
                 logging.error('failed to remount root partition rw: %s' % e, exc_info=True)
         
-        if not os.access(settings.PROJECT_PATH, os.W_OK):
-            raise Exception('path "%s" is not writable' % settings.PROJECT_PATH)
+        if not os.access(path, os.W_OK):
+            raise Exception('path "%s" is not writable' % path)
         
         # download the archive
         archive = download(version)
@@ -172,7 +174,25 @@ def perform_update(version):
         logging.debug('extracting archive %(archive)s...' % {'archive': archive})
         os.system('tar zxf %(archive)s -C %(path)s' % {
                 'archive': archive, 'path': temp_path})
-            
+        
+        # kill all the subprocesses
+        try:
+            children_pids = [int(p) for p in subprocess.check_output('ps -o pid --no-headers --ppid %s' % os.getpid(), shell=True).split() if p]
+            for pid in children_pids:
+                try:
+                    os.kill(pid, signal.SIGKILL)
+                    logging.debug('killed process %d' % pid)
+                
+                except Exception as e:
+                    if getattr(e, 'errno', None) == 3: # no such process
+                        continue
+                    
+                    else:
+                        logging.error('failed to kill process %d: %s' % (pid, e))
+
+        except Exception as e:
+            logging.error('failed to kill children processes: %s' % e)
+        
         # determine the root path of the extracted archive
         root_name = [f for f in os.listdir(temp_path) if os.path.isdir(os.path.join(temp_path, f))][0]
         root_path = os.path.join(temp_path, root_name)