[platform] exception logging in Unix restarter script
[idea/community.git] / bin / linux / restart.py
1 #!/usr/bin/env python
2
3 # Waits for the parent process to terminate, then executes specified commands.
4
5 import os
6 import signal
7 import sys
8 import syslog
9 import time
10
11 if len(sys.argv) < 3:
12     raise Exception('usage: restart.py <pid> <path> [optional command]')
13
14 try:
15     signal.signal(signal.SIGHUP, signal.SIG_IGN)
16
17     pid = int(sys.argv[1])
18     while os.getppid() == pid:
19         time.sleep(0.5)
20
21     if len(sys.argv) > 3:
22         to_launch = sys.argv[3:]
23         os.spawnv(os.P_WAIT, to_launch[0], to_launch)
24
25     to_launch = ['/usr/bin/open', sys.argv[2]] if sys.platform == 'darwin' else [sys.argv[2]]
26     os.execv(to_launch[0], to_launch)
27 except:
28     syslog.syslog(syslog.LOG_ERR, str(sys.exc_info()))