[platform] exception logging in Unix restarter script
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Fri, 1 Sep 2017 06:30:52 +0000 (09:30 +0300)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Fri, 1 Sep 2017 06:35:47 +0000 (09:35 +0300)
bin/linux/restart.py

index 5d49a22c38205d7dab13b21c3ec848dc0cc020c4..241e5a187cde2c64a0c883bae05c32c3a8c9447a 100755 (executable)
@@ -5,20 +5,24 @@
 import os
 import signal
 import sys
+import syslog
 import time
 
 if len(sys.argv) < 3:
     raise Exception('usage: restart.py <pid> <path> [optional command]')
 
-signal.signal(signal.SIGHUP, signal.SIG_IGN)
+try:
+    signal.signal(signal.SIGHUP, signal.SIG_IGN)
 
-pid = int(sys.argv[1])
-while os.getppid() == pid:
-    time.sleep(0.5)
+    pid = int(sys.argv[1])
+    while os.getppid() == pid:
+        time.sleep(0.5)
 
-if len(sys.argv) > 3:
-    to_launch = sys.argv[3:]
-    os.spawnv(os.P_WAIT, to_launch[0], to_launch)
+    if len(sys.argv) > 3:
+        to_launch = sys.argv[3:]
+        os.spawnv(os.P_WAIT, to_launch[0], to_launch)
 
-to_launch = ['/usr/bin/open', sys.argv[2]] if sys.platform == 'darwin' else [sys.argv[2]]
-os.execv(to_launch[0], to_launch)
+    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()))