[dynamic plugins] application level #IDEA-246104
[idea/community.git] / bin / linux / restart.py
index 96397f82b9467ca923d4351082511060eeb4f83c..57f0b1d1f11a56161883f6a69055047c30675233 100755 (executable)
@@ -3,21 +3,28 @@
 # Waits for the parent process to terminate, then executes specified commands.
 
 import os
+import signal
 import sys
+import syslog
 import time
 
 if len(sys.argv) < 3:
     raise Exception('usage: restart.py <pid> <path> [optional command]')
 
-pid = int(sys.argv[1])
-while os.getppid() == pid:
-    time.sleep(0.5)
+try:
+    signal.signal(signal.SIGHUP, signal.SIG_IGN)
 
-if len(sys.argv) > 3:
-    os.spawnv(os.P_WAIT, sys.argv[3], sys.argv[3:])
+    pid = int(sys.argv[1])
+    while os.getppid() == pid:
+        time.sleep(0.5)
 
-to_launch = sys.argv[2]
-if sys.platform == 'darwin':
-    os.execv('/usr/bin/open', ['/usr/bin/open', to_launch])
-else:
-    os.execv(to_launch, [to_launch])
+    if len(sys.argv) > 3:
+        to_launch = sys.argv[3:]
+        ec = os.spawnv(os.P_WAIT, to_launch[0], to_launch)
+        if ec != 0:
+            syslog.syslog(syslog.LOG_ERR, str(to_launch) + ': ' + str(ec))
+
+    to_launch = ['/usr/bin/open', sys.argv[2]] if sys.platform == 'darwin' else [sys.argv[2]]
+    os.execv(to_launch[0], to_launch)
+except:
+    syslog.syslog(syslog.LOG_ERR, str(sys.exc_info()))